hello friends,
was just wondering it would be gr8 to make a VB program which controls what is drawn in AutoCAD ...... hmmmm interesting.....So i went through developer help in AutoCAD and finally managed to have a basic level of AutoCAD customization and some VB coding which i like to do...
So here is the pie....
1. Tools used were: AutoCAD2010 and VBAIDE which now we need to download from Autodesk website:
http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=12715668&linkID=9240618
which enables VBA in AutoCAD2010...
Objectives: adding a tool menu in AutoCAD called ICS and put a button as sub menu called 'circle' which when selected will trigger the VB program and i could do some simple stuff in AutoCAD using that VB program...
Firstly, how to add a menu in existing AutoCAD window.....i.e. things like File, Edit, View.......Help, Express.....and my own ICS ..... :)
For this just give a simple command 'CUI' at the command prompt of the AutoCAD....
window with a lot of stuff will fire up on screen.... just go to transfer tab of the same and use the button used for creating a new customization file......... ICS.cuix ............ basically this file contains information about how the different menus and commands are associated to each other in AutoCAD......... ( hmmmm AutoCAD has its own default cuix file too, so make sure you don't modify it unnecessarily )
ICS1
click image to view better...
ICS2
now go to tools--> macro--> macros (alt+F8)
you ll see the blank macro window...just type 'ccc' in macro name and create button to create macro called 'ccc' ......... now press vbamanager......then vba editor.......and you will see the usual vb IDE........ then the stage is yours..........
I just put some code and made a simple program......that draws a circle at 0,0,0 and radius entered at program, also it draws a diametric dimension at 45 degrees to the circle drawn.......and zoom extents the CAD window...
here is the snap shot of it......and the code....
code: Private Sub CommandButton1_Click()
Dim circleobj As AcadCircle
Dim C(0 To 2) As Double
C(0) = 0: C(1) = 0: C(2) = 0
R = TextBox1.Value
Set circleobj = ThisDrawing.ModelSpace.AddCircle(C, R)
Dim dimObj As AcadDimDiametric
Dim CP(0 To 2) As Double
Dim FP(0 To 2) As Double
Dim LL As Double
' Define the dimension
CP(0) = -((Math.Cos(45 / 180 * 3.14)) * R): CP(1) = -((Math.Sin(45 / 180 * 3.14)) * R): CP(2) = 0#
FP(0) = ((Math.Cos(45 / 180 * 3.14)) * R): FP(1) = ((Math.Sin(45 / 180 * 3.14)) * R): FP(2) = 0#
leaderLength = 20#
' Create the diametric dimension in model space
Set dimObj = ThisDrawing.ModelSpace.AddDimDiametric(CP, FP, LL)
ZoomExtents
End Sub
module1 code:
Sub ccc()
UserForm1.Show
End Sub
and my simple stuff snapshot is like this:
click image to view better...
was just wondering it would be gr8 to make a VB program which controls what is drawn in AutoCAD ...... hmmmm interesting.....So i went through developer help in AutoCAD and finally managed to have a basic level of AutoCAD customization and some VB coding which i like to do...
So here is the pie....
1. Tools used were: AutoCAD2010 and VBAIDE which now we need to download from Autodesk website:
http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=12715668&linkID=9240618
which enables VBA in AutoCAD2010...
Objectives: adding a tool menu in AutoCAD called ICS and put a button as sub menu called 'circle' which when selected will trigger the VB program and i could do some simple stuff in AutoCAD using that VB program...
Firstly, how to add a menu in existing AutoCAD window.....i.e. things like File, Edit, View.......Help, Express.....and my own ICS ..... :)
For this just give a simple command 'CUI' at the command prompt of the AutoCAD....
window with a lot of stuff will fire up on screen.... just go to transfer tab of the same and use the button used for creating a new customization file......... ICS.cuix ............ basically this file contains information about how the different menus and commands are associated to each other in AutoCAD......... ( hmmmm AutoCAD has its own default cuix file too, so make sure you don't modify it unnecessarily )
after creating ICS.cuix somewhere on u r hard drive (as shown in fig. ICS1)....get back to customize tab of the window and select the ICS.cuix file from drop down menu as shown in fig. ICS2 and use the create new command button to create command called 'circle'.........change things as shown and most importantly ' vbarun ccc' ............this means the button pressed will cause macro called 'ccc' shall run when button pressed...
click image to view better...
click image to view better...
ICS1
click image to view better...
ICS2
now go to tools--> macro--> macros (alt+F8)
you ll see the blank macro window...just type 'ccc' in macro name and create button to create macro called 'ccc' ......... now press vbamanager......then vba editor.......and you will see the usual vb IDE........ then the stage is yours..........
I just put some code and made a simple program......that draws a circle at 0,0,0 and radius entered at program, also it draws a diametric dimension at 45 degrees to the circle drawn.......and zoom extents the CAD window...
here is the snap shot of it......and the code....
code: Private Sub CommandButton1_Click()
Dim circleobj As AcadCircle
Dim C(0 To 2) As Double
C(0) = 0: C(1) = 0: C(2) = 0
R = TextBox1.Value
Set circleobj = ThisDrawing.ModelSpace.AddCircle(C, R)
Dim dimObj As AcadDimDiametric
Dim CP(0 To 2) As Double
Dim FP(0 To 2) As Double
Dim LL As Double
' Define the dimension
CP(0) = -((Math.Cos(45 / 180 * 3.14)) * R): CP(1) = -((Math.Sin(45 / 180 * 3.14)) * R): CP(2) = 0#
FP(0) = ((Math.Cos(45 / 180 * 3.14)) * R): FP(1) = ((Math.Sin(45 / 180 * 3.14)) * R): FP(2) = 0#
leaderLength = 20#
' Create the diametric dimension in model space
Set dimObj = ThisDrawing.ModelSpace.AddDimDiametric(CP, FP, LL)
ZoomExtents
End Sub
module1 code:
Sub ccc()
UserForm1.Show
End Sub
and my simple stuff snapshot is like this:
click image to view better...
Informative Post. thanks For Sharing this Post. Keep It Up. Keep posting. Otherwise anyone wants to Learn Staad Pro Training Course so, Contact here- +91-9311002620 or visit website- https://www.htsindia.com/Courses/cad-cam-cae/autocad-staad-pro-v8i-engineer-wildfire-training-course
ReplyDelete