Using COM objects and Python to Draw a Polyline

#1
I have been trying to figure out how to use COM objects and Python to interact with IntelliCAD. I have been able to create new layers, lines and text in Intellicad with Python but I haven't been able to figure out how to draw a polyline. Here is my code:

Code: Select all

import win32com.client

# Create an instance of IntelliCAD
icad = win32com.client.Dispatch("Icad.Application")

# Make the IntelliCAD application visible
icad.Visible = True

# Get the current document
doc = icad.ActiveDocument
print(doc.Name)

# Create a new layer
doc.Layers.Add('New Layer')

# Create points
p1 = icad.Library.CreatePoint(0, 0)
p2 = icad.Library.CreatePoint(10, 10)
p3 = icad.Library.CreatePoint(10, 0)

# Draw line
line = doc.ModelSpace.AddLine(p1, p2)

# Draw Text
text = doc.ModelSpace.AddText('Hello World', p1, 1)

# Draw Polyline
pline = doc.ModelSpace.AddPolyLine([p1, p2, p3])
All but the last line to draw a polyline works. The last line returns a 'Type mismatch' error. Any help with this is appreciated.

Re: Using COM objects and Python to Draw a Polyline

#2
I just figured this out. I found a VBA example for creating a polyline in the IntelliCAD Developer Reference. It shows that you must use Library.CreatePoints() method rather than Library.CreatePoint(). I was able to get this to work the following python code:

Code: Select all

 #Create Points
points = icad.Library.CreatePoints()
points.Add()
points[0].x = 0
points[0].y = 0
points.Add()
points[1].x = 10
points[1].y = 10
points.Add()
points[2].x = 10
points[2].y = 0

# Draw Polyline
pline = doc.ModelSpace.AddPolyLine(points)