progeCAD support, tips and troubleshooting forum. progeCAD works very similar to some versions of AutoCAD. Moderated.

Moderators: caddit, Moderators

#2145 by thomasullmann
Tue May 13, 2014 7:08 am
i want to creat a new line by selecting start and endpoint. at last i want to Change the Color of the line in red. With AutoCAD vba it works fine, but with progcad the message "run-time error 424 object required" appears. after checking the "end" button the line will be created.

here is the used code

Sub line_create_and_change_in_red()

Dim MyDok As Document
Dim Myline As Line
Set MyDok = Application.ActiveDocument

Set p1 = MyDok.Utility.GetPoint(, "Anfangspunkt: ")
Set p2 = MyDok.Utility.GetPoint(, "Endpunkt: ")

Set Myline = MyDok.ModelSpace.AddLine(p1, p2)
Myline.color = Red

End Sub[code]

#2146 by Finite
Tue May 13, 2014 10:54 pm
Try

Sub line_create_and_change_in_red()

Dim MyDok As Document
Dim Myline As Line
Set MyDok = Application.ActiveDocument

Set p1 = MyDok.Utility.GetPoint(, "Anfangspunkt: ")
Set p2 = MyDok.Utility.GetPoint(, "Endpunkt: ")

Set Myline = MyDok.ModelSpace.AddLine(p1, p2)
'Myline.Color = Red
Myline.Color = vicRed
Myline.Update

End Sub

#2147 by thomasullmann
Wed May 14, 2014 7:08 am
thank you John

i've already tryed this but the error

Copile error: Type mismatch

appears.

#2148 by Finite
Wed May 14, 2014 11:17 pm
Do you have Option Explicit at the start of the Module?

This means you need to Define your Variables such as:

Dim p1 as Intellicad.point

Also the [code] after End Sub will cause a compile error.

#2149 by thomasullmann
Thu May 15, 2014 12:04 pm
Thank you all together i've found the mistake.

the correct fil is
Myline.color.ColorIndex = vicBlue

not only
myline.color=vicBlue
#2150 by thomasullmann
Thu May 15, 2014 3:11 pm
hallo

i would like to draw a line by the coordinates x and y

her my first try

Sub line_zeichnen()

Dim Punkt1(0 To 2) As Double
Dim Punkt2(0 To 2) As Double
Dim MyDok As Document
Dim Myline As Line

Set MyDok = Application.ActiveDocument

Punkt1(0) = 0
Punkt1(1) = 0
Punkt1(2) = 0

Punkt2(0) = 100
Punkt2(1) = 200
Punkt2(2) = 0

Set Myline = MyDok.ModelSpace.AddLine(Punkt1, Punkt2)

End Sub

the error is "Type mismatch"

can somebody help me? whats wrong in the code? I already tryed
it with a 2-dimensions arrey, also the same mistake

#2151 by Finite
Thu May 15, 2014 11:42 pm
There are differences between AutoCAD and IntelliCAD VBA.

In AutoCAD VBA points are an array of doubles.

In IntelliCAD VBA a point is an object with its own methods and properties.

The properties a point include x, y and z

Try:

Sub TestPoint()

Dim MyDok As Document
Dim Myline As Line

Set MyDok = Application.ActiveDocument

Dim Punkt1 As IntelliCAD.Point
Dim Punkt2 As IntelliCAD.Point

'Set properties of Test Point 1
Set Punkt1 = Library.CreatePoint(0, 0, 0)


'Set properties of Test Point 2
Set Punkt2 = Library.CreatePoint(100#, 200#, 0#)


Set Myline = MyDok.ModelSpace.AddLine(Punkt1, Punkt2)
Myline.Update

MsgBox "Point 2 x = " & Punkt2.x & " Point 2 y = " & Punkt2.y


End Sub

#2152 by thomasullmann
Fri May 16, 2014 4:46 am
ok, it works...

but now i would like to create a lwpolyline with the same coordinates. how to manage this? (sorry i'm just a beginner)

#2153 by Finite
Fri May 16, 2014 7:14 am
You should look at the Help in VBA here is an example that will get you started:

AddPolyline method example
Private Sub Polyline_Example()

' This example adds a polyline to the drawing using the AddPolyline method.

Dim myDoc As progeCAD.Document

Dim myPline As Polyline

Dim myPoints As points

Dim pt As Point

Set myDoc = ActiveDocument

Set myPoints = Library.CreatePoints

Set pt = Library.CreatePoint(1, 1, 0)

myPoints.Add

myPoints(myPoints.Count).x = pt.x

myPoints(myPoints.Count).y = pt.y

myPoints(myPoints.Count).z = pt.z

Set pt = Library.CreatePoint(3, 3, 0)

myPoints.Add

myPoints(myPoints.Count).x = pt.x

myPoints(myPoints.Count).y = pt.y

myPoints(myPoints.Count).z = pt.z

Set myPline = ThisDocument.ModelSpace.AddPolyline(myPoints)

myPline.Update

ThisDocument.ActiveViewport.ZoomExtents

End Sub

#2154 by thomasullmann
Fri May 16, 2014 11:16 am
hallo John, thank you

i've already find this examle on the helppage end tested it, also the same proglem. hear is the code

Sub polylinie_erstellen()

Dim myDoc As IntelliCAD.Document
Dim myPline As IntelliCAD.Polyline
Dim myPoints As IntelliCAD.points
Dim pt As IntelliCAD.Point
Set myDoc = ActiveDocument
Set myPoints = Library.CreatePoints
Set pt = Library.CreatePoint(100, 200, 0)

MsgBox "x-value point 1: " & pt.x & Chr(13) & _
"y-value point 1: " & pt.y & Chr(13) & _
"z-value point 1: " & pt.z

myPoints.Add


up to here it' all ok

myPoints(myPoints.Count).x = pt.x Here the error Comes "runtime error 5

after "myPoints.Add" a new collection is made, the cound and item is 1
the 3 coordinates where 0.
i cant find the mistake. or should i better work witz the progecad-library, wich i do not have at the moment