manipulating acad commands with vba

manipulating acad commands with vba

Anonymous
Not applicable
863 Views
2 Replies
Message 1 of 3

manipulating acad commands with vba

Anonymous
Not applicable

greetings,

 

I am trying to call a command with vba but I dont want any user interaction for example I am running the pedit command. I want it to use multiple adn then select all and then join the new plines. 

 

Is it possible to run autocad commands and select their options from vba? 

 

thanks!!

0 Likes
Accepted solutions (1)
864 Views
2 Replies
Replies (2)
Message 2 of 3

Alfred.NESWADBA
Consultant
Consultant
Accepted solution

Hi,

 

What you are looking for can be done with SendCommand like that (this sample closes all polylines)

Public Sub test()
   Call ThisDrawing.SendCommand("_PEDIT" & vbCr & "_multiple" & _
            vbCr & "_all" & vbCr & vbCr & "_close" & vbCr & vbCr)
End Sub

 

But be careful: whenever possible avoid to use SendCommand and the command-line interface as you don't get feedback then.

In the above example if there are not only polylines in your drawing you will get a question "convert lines ... to polylines" and that question is not handled, so the complete following sequence fails. Other critical thing might be that there is no polyline in the drawing, ... and so on.

 

Depending on what you want to do with the polylines the preferred way is always to use the API for polylines to modify them to get what you need.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 3

Anonymous
Not applicable

Thank you for your help this worked perfectly. 

 

i have this code that prompts the user for the starting pointof a line is there a way to preset the starting point to 0, 0, 0

 

Private Sub CommandButton1_Click()
UserForm2.Hide

pt1 = ThisDrawing.Utility.GetPoint(, "set start point")
pt2 = ThisDrawing.Utility.PolarPoint(pt1, 0, Val(TextBox1.Text))
pt3 = ThisDrawing.Utility.PolarPoint(pt2, pi / 2, Val(TextBox2.Text))
pt4 = ThisDrawing.Utility.PolarPoint(pt1, pi / 2, Val(TextBox2.Text))

ThisDrawing.ModelSpace.AddLine pt1, pt2
ThisDrawing.ModelSpace.AddLine pt2, pt3
ThisDrawing.ModelSpace.AddLine pt3, pt4
ThisDrawing.ModelSpace.AddLine pt4, pt1

Unload Me
End Sub

 

 

Thanks again!!

0 Likes