Search the Community
Showing results for tags 'autocad vba'.
-
Adding layers and setting properties from VBA macro
sritter09 posted a topic in .NET, ObjectARX & VBA
I know a lot of AutoCAD users find themselves doing the same functions over and over. Most of us can type the command prompts blindfolded and finish half the drawing. I am just starting out with VBA for AutoCAD (I've done some pretty involved VBA for excel if anyone needs help with that) so I figured I would post an example of my "hello world" macro for Mechanical 2017. Our company uses boundary lines around our views in model space and here is a way to add a new layer, change the color, and turn off plot. I use it when I'm updating older drawings. Sub ADD_NOPLOT() Dim oNEWLAYER As AcadLayer On Error Resume Next Set oNEWLAYER = ThisDrawing.Layers.Add("NO_PLOT") oNEWLAYER.color = acMagenta oNEWLAYER.Plottable = False End Sub Sorry there wasn't a question in all that. I just figured since it took me a couple searches to piece it together I would share it with all of you. -
Hi, I have a good experience in AutoCAD but no skills in programming, I just started with Acad VBA (Sorry my English is basic as well). I started by some simples programs, as creating drawing geometries... Now, I would like to know how build a code for selecting objects in the drawing. I tested this program (see below) and many others to understand the logical; I had every time an error on the same line (in red). I learned that this line is for attributing a new dimension to ssetObj object. but, What is the problem? Could someone help me? Thanks [color=#303030][font=Tahoma]Private Sub CommandButton3_Click()[/font][/color] [color=#303030][font=Tahoma]Dim ssetobj As AcadSelectionSet[/font][/color] [color=#303030][font=Tahoma]'On Error Resume Next[/font][/color] [font=Tahoma][color=red]Set ssetobj = ThisDrawing.SelectionSets.Add("SS01")[/color][/font] [color=#303030][font=Tahoma]frmForm1.Hide[/font][/color] [color=#303030][font=Tahoma]ssetobj.SelectOnScreen[/font][/color] [color=#303030][font=Tahoma]ssetobj.Erase[/font][/color] [color=#303030][font=Tahoma]frmForm1.Show[/font][/color] [color=#303030][font=Tahoma]End Sub[/font][/color] [font=Tahoma][color=#303030] [/color][/font]
-
Open .dwg files from combobox with AutoCAD 2010 VBA
suwan116 posted a topic in .NET, ObjectARX & VBA
Hey Guys! Im new to AutoCAD and VBA. My task is to develop an autocad add on program that will allow a user to insert a customised project drawing frame. I have setup the userform where a user can click on the combo box and select a drawing frame (in this case A4, A4 Portrait, A3 and A1) and click the insert button, which will then display the frame in PaperSpace. Currently i have used some code which enables me to bring up the drawing frame and display it in PaperSpace, however the code only allows me to bring up one of the frames. Im not sure how to change the code so the use can chose which frame they would like. Heres the code i have so far: Private Sub CommandButton2_Click() Dim myBlock As AcadBlockReference Dim blockInsert(0 To 2) As Double blockInsert(0) = -18 blockInsert(1) = -6 blockInsert(2) = 0 Set myBlock = ThisDrawing.PaperSpace.InsertBlock(blockInsert, "C:\Drawing Frame\A1_Frame.dwg", 1, 1, 1, 0) End Sub As you can see from the code, it will only bring up the A1 Frame. How could i edit this code so the end user could use the drop down to select a desired frame. I hope this makes sence and hope you could help me with this. Cheers!