"Read" DWGs in Dynamo as ActiveX.GetCOMObjects: properties & methods

Hey everybody,
I am trying to read specific object properties from AutoCad files (geometry, coordinates,layers, etc), but I can’t get my head around polylines with different widths. I already tried exporting data from AutoCAD and then feeding it to Dynamo but it still lacks information I am really iterested in.
In the following screenshots I am testing my workflow with the package “LinkDWG” and opening a desidered CAD file in AutoCad while working in Dynamo.
For simplyicity I will only consider one object (a polyline). Please excuse my poor Python skills and the lengthy post.

If the polyline has a constant width then I am able to read it:


If the polyline has different widths I (obviously) get an error:
image

I tried to examine this link (foud inside LinkDWG’s nodes) but had little success. I then googled and found this better link to refer to.

I came to understand that unfortunately the start and end widths of each polyline segments are not a property of the polyline itself. I tried then to use the “GetWidth”, “SetWidth” and “GetBulge” methods to try to understand somethig:

Let’s start with the GetBulge method (not-NSFW):

Gets the bulge value at a given index of the polyline.
SIGNATURE:
VBA:
RetVal = object.GetBulge(Index)
object Type: LWPolyline, Polyline
The objects this method applies to.
Index
Access*: Input-only
Type: Integer
The index location of the vertex you wish to query. The index must be a positive integer beginning with zero.
RETURN VALUE (RetVal):
Type: Double
The bulge value for the vertex at the given index.

The bulge is the tangent of 1/4 of the included angle for the arc between the selected vertex and the next vertex in the polyline’s vertex list. A negative bulge value indicates that the arc goes clockwise from the selected vertex to the next vertex. A bulge of 0 indicates a straight segment, and a bulge of 1 is a semicircle.

This method has a return value so I can do this:

Ok perfect, let’s try to do the same with the GetWidths method (link):

Gets the start and end width for a polyline.
SIGNATURE:
VBA:
object.GetWidth Index, StartWidth, EndWidth
object Type: LWPolyline, Polyline
The objects this method applies to.
1) Index
Access: Input-only
Type: Integer
The index location of the polyline for which the width is returned. The index must be a positive integer beginning with 0.
2) StartWidth
Access: OUTPUT-only
Type: Double
The start width of the polyline at the given index.
3) EndWidth
Access: OUTPUT-only
Type: Double
The end width of the polyline at the given index.
RETURN VALUE (RetVal):
NO RETURN VALUE

What bothers me first of all is the absence of parenthesis, but I guess it’s just something Visual Basic-related. Then I noticed that this method has no return value, and that its arguments are both inputs and outputs.

I tried stating an inital value (null and number) and then applied the method like this but with no success:


the outputs are my initial inputs. If I do not state them, or state them as empty lists I obviously get errors.

I then tried to play around with the SetWidth method which is similar to the GetWidth one but with only inputs, and to my suprise I was able to change the widths in autocad but I still could not read them in dynamo (i still get the initial inputs as outputs).

Simple Python script
obj=IN[0] #my test poyline
NewWdth=IN[1]

n=len(obj.Coordinates)/2-1	#number of polyline "segments" (number of x+y point coordinates minus 1)

a=None #random start value
b=66.6 #random start value
startWidths=[]
endWidths=[]
newWidths=[]
i=0

for i in range (0,n):
	obj.SetWidth(i,i*NewWdth,i*NewWdth) #random operation to modify the polyline segments' widths
	obj.GetWidth(i,a,b) #TRY to read the polyline segments' new widths
	startWidths.append(a)
	endWidths.append(b)
	newWidths.append(i*NewWdth)

OUT=[startWidths,endWidths,newWidths]

Does anybody know what I am missing? (a part from a thorough knowledge of python, autocad api, vba, etc etc :slight_smile: ) How can I read the outputs of a method with no return value?
Thanks!

Ps. At least I found out I can use Dynamo to work in the AutoCAD environment!

Maybe I found a solution:
I had to initialize the outputs as clr.Reference[float]() and then read their value (.Value)


Do not really know why but it works. Is there a better way of doing it?

Anyone help me with this dynamo I am new to this so I can’t find this ActiveX.GetCOMObjects on my dynamo so anyone help how to get that.