(Solved)How to use purebasic to operate autocad?
(Solved)How to use purebasic to operate autocad?
Hello everyone ,my major job is industry designing.so i need many tools to make my job more efficient,for example:excel ,autocad,solidworks etc...
I bought the purebasic several months ago,i think it's simple and powerful.But it's not an OOP language.fortunately,there is ComatePlus to use COM to opreate these tools.Now,i am familiar with excel,because i have demos,but ComatePlus doesn't give the demo for autocad and solidworks.Would you like to give me some demos to learn to operate autocad or solidworks ??Thanks a lot.
I bought the purebasic several months ago,i think it's simple and powerful.But it's not an OOP language.fortunately,there is ComatePlus to use COM to opreate these tools.Now,i am familiar with excel,because i have demos,but ComatePlus doesn't give the demo for autocad and solidworks.Would you like to give me some demos to learn to operate autocad or solidworks ??Thanks a lot.
Last edited by ryan777 on Mon Aug 15, 2022 4:08 am, edited 2 times in total.
- captain_skank
- Enthusiast
- Posts: 636
- Joined: Fri Oct 06, 2006 3:57 pm
- Location: England
Re: How to use purebasic to operate autocad?
Hi,
First up you would have to check if the program you want to interface with allows external access ( has an API )
Autocad does http://docs.autodesk.com/ACD/2010/ENU/A ... index.html
Solidworks also has an API but you need to be a registered user to access info on it.
You will then need to figure out how to interface between PB and the API so you can interact with it, ComatePlus may be the answer or you may have to wite something from scratch.
Technicaly this is way beyond my competence level though.
Cheers
First up you would have to check if the program you want to interface with allows external access ( has an API )
Autocad does http://docs.autodesk.com/ACD/2010/ENU/A ... index.html
Solidworks also has an API but you need to be a registered user to access info on it.
You will then need to figure out how to interface between PB and the API so you can interact with it, ComatePlus may be the answer or you may have to wite something from scratch.
Technicaly this is way beyond my competence level though.
Cheers
Re: How to use purebasic to operate autocad?
You could have a look at this https://www.purebasic.fr/english/viewto ... 96#p570696
The OP never replied so I've no idea if it actually works, but it might give you some clues...
Somewhere along the line you may need to understand how variant variables actually work so do some homework if you don't know this already.
https://en.wikipedia.org/wiki/Variant_type_(COM)
The OP never replied so I've no idea if it actually works, but it might give you some clues...
Somewhere along the line you may need to understand how variant variables actually work so do some homework if you don't know this already.
https://en.wikipedia.org/wiki/Variant_type_(COM)
Re: How to use purebasic to operate autocad?
hello,i tried this demo,and it gave me this debug output:spikey wrote: ↑Tue Aug 02, 2022 2:41 pm You could have a look at this viewtopic.php?p=570696#p570696
The OP never replied so I've no idea if it actually works, but it might give you some clues...
Somewhere along the line you may need to understand how variant variables actually work so do some homework if you don't know this already.
https://en.wikipedia.org/wiki/Variant_type_(COM)
"#S_OK
#S_OK
#S_OK
#S_OK
#S_OK
#S_OK
Couldn't start AutoCAD.
Invalid progID/CLSID. Check your spelling of the programmatic identifier. Also check that the component / ActiveX control has been registered."
Would you like to help me to analyse this situation? thanks a lot!
Re: How to use purebasic to operate autocad?
I'd guess you've got a different version of AutoCAD from the OP. First off you can try replacing "AutoCAD.Application.16" with just "AutoCAD.Application" without a version number. If that doesn't work you'll need to consult the documentation you have with your version or the system registry to find out the right name for the object. Search the registry for "AutoCAD.Application" and look for one that is followed by a number other than 16. Update with the right version number and try again.
Re: How to use purebasic to operate autocad?
Thank you a lot,the app get over this problem now.But the debug output gave me new appearance:spikey wrote: ↑Wed Aug 10, 2022 6:23 pm I'd guess you've got a different version of AutoCAD from the OP. First off you can try replacing "AutoCAD.Application.16" with just "AutoCAD.Application" without a version number. If that doesn't work you'll need to consult the documentation you have with your version or the system registry to find out the right name for the object. Search the registry for "AutoCAD.Application" and look for one that is followed by a number other than 16. Update with the right version number and try again.
"#S_OK
#S_OK
#S_OK
#S_OK
#S_OK
#S_OK
Make it visible.
Okay.
Get the active document.
Okay.
Add a line to the document.
One or more arguments are invalid. Possibly a numerical overflow or too many nested objects, -if so, try splitting your method call into two or more subcalls.
Invoke zoom extents when you've got the right parent object."
what's the meaning of these words? thanks again!
Re: How to use purebasic to operate autocad?
I just tried this ...
Code: Select all
XIncludeFile #PB_Compiler_Home+"Include\Comateplus.pbi"
Enumeration
#Window
EndEnumeration
Enumeration
#ExplorerList
#Combo_Save
#Button_0
#Frame3D_0
#Frame3D_1
EndEnumeration
Global value
Procedure.s GetFilePartWithoutExtension(File.s) ; Procedure by NictheQuick
Protected *c.Character = @File, tmp.s = "", Result.s
While *c\c
If *c\c = '\'
tmp = ""
Result = ""
ElseIf *c\c = '.'
Result = tmp
tmp + Chr(*c\c)
Else
tmp + Chr(*c\c)
EndIf
*c + SizeOf(Character)
Wend
If Result
ProcedureReturn Result
Else
ProcedureReturn tmp
EndIf
EndProcedure
Procedure save()
Protected autocad.COMateObject
Protected document.COMateObject
Protected open.COMateObject
Protected activeDoc.COMateObject
autocad = COMate_CreateObject("autocad.application")
If autocad
OpenConsole()
document = autocad\GetObjectProperty("Documents")
;************
For i=0 To CountGadgetItems(#ExplorerList)-1
If GetGadgetItemState(#ExplorerList, i)&#PB_Explorer_Selected
file.s=GetGadgetItemText(#ExplorerList, i)
path.s=GetGadgetText(#ExplorerList)
open = document\GetObjectProperty("open('"+path+file+"', 1)")
savefile.s=path+"_"+GetFilePartWithoutExtension(file)
Print(file+".....")
If open
activeDoc = open\GetObjectProperty("Application\ActiveDocument")
If activeDoc
activeDoc\Invoke("SaveAs('"+savefile+"',"+Str(value)+")")
activeDoc\Release()
PrintN("saved")
Else
MessageRequester("Sorry!", "File not saved!")
EndIf
open\release()
Else
MessageRequester("Sorry!", "File couldn`t be openend!")
EndIf
EndIf
Next
document\release()
autocad\Invoke("Quit")
autocad\release()
CloseConsole()
Else
MessageRequester("Fehler!", "AutoCad muss installiert sein!")
EndIf
EndProcedure
Procedure Open_Window()
If OpenWindow(#Window, 335, 45, 400, 465, "AutoCad converter", #PB_Window_SystemMenu|#PB_Window_TitleBar )
ExplorerListGadget(#ExplorerList, 40, 35, 320, 300, "C:\*.dwg;*.dxf", #PB_Explorer_AlwaysShowSelection|#PB_Explorer_MultiSelect|#PB_Explorer_FullRowSelect|#PB_Explorer_AutoSort)
RemoveGadgetColumn(#ExplorerList, 2)
SetGadgetItemAttribute(#ExplorerList, 0, #PB_Explorer_ColumnWidth, 190, 0)
SetGadgetItemAttribute(#ExplorerList, 0, #PB_Explorer_ColumnWidth, 60, 1)
SetGadgetItemAttribute(#ExplorerList, 0, #PB_Explorer_ColumnWidth, 99, 2)
ComboBoxGadget(#Combo_Save, 40, 390, 225, 20)
AddGadgetItem(#Combo_Save, -1 , "AutoCAD Release12/LT2 DXF (*.dxf)")
AddGadgetItem(#Combo_Save, -1 , "AutoCAD Release13/LT95 DWG (*.dwg)")
AddGadgetItem(#Combo_Save, -1 , "AutoCAD Release13/LT95 DXF (*.dxf)")
AddGadgetItem(#Combo_Save, -1 , "AutoCAD Release14/LT97 DWG (*.dwg)")
AddGadgetItem(#Combo_Save, -1 , "AutoCAD Release14/LT97 DXF (*.dxf)")
AddGadgetItem(#Combo_Save, -1 , "AutoCAD 2000 DWG (*.dwg)")
AddGadgetItem(#Combo_Save, -1 , "AutoCAD 2000 DXF (*.dxf)")
AddGadgetItem(#Combo_Save, -1 , "AutoCAD 2000 DWT (*.dwt)")
AddGadgetItem(#Combo_Save, -1 , "AutoCAD 2004 DXF (*.dxf)")
AddGadgetItem(#Combo_Save, -1 , "AutoCAD 2004 DWG (*.dwg)")
AddGadgetItem(#Combo_Save, -1 , "AutoCAD 2004 DWT (*.dwt)")
SetGadgetState(#Combo_Save, 6)
Frame3DGadget(#Frame3D_0, 20, 365, 360, 65, "Save as version")
ButtonGadget(#Button_0, 285, 390, 75, 25, "save")
Frame3DGadget(#Frame3D_1, 20, 15, 360, 340, "")
EndIf
EndProcedure
Open_Window()
Repeat
event=WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case #Button_0
Select GetGadgetState(#Combo_Save)
Case 0: value=1
Case 1: value=4
Case 2: value=5
Case 3: value=8
Case 4: value=9
Case 5: value=12
Case 6: value=13
Case 7: value=14
Case 8: value=24
Case 9: value=25
Case 10: value=26
EndSelect
save()
EndSelect
EndSelect
Until event=#PB_Event_CloseWindow
PureBasic for Windows
-
- Addict
- Posts: 1309
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: How to use purebasic to operate autocad?
I do not know if this will help.
I did some Autocad work many years ago, mainly electric control panel design which broke down into a list of standard blocks, about 200 of them.
After a lot of messing around I used the Autocad DXF format just a straight forward text file.
I first created the blocks in Autocad and exported them in dxf format.
Then it was just a problem of combining the blocks in the right order and the right place in the dxf file then start Autocad and read in the dxf file.
When I did some work on maps and architectural drawings I learnt a little lisp and automated my copy of Autocad using this, thankfully just deleting areas and cutting out to make separate drawings.
I did some Autocad work many years ago, mainly electric control panel design which broke down into a list of standard blocks, about 200 of them.
After a lot of messing around I used the Autocad DXF format just a straight forward text file.
I first created the blocks in Autocad and exported them in dxf format.
Then it was just a problem of combining the blocks in the right order and the right place in the dxf file then start Autocad and read in the dxf file.
When I did some work on maps and architectural drawings I learnt a little lisp and automated my copy of Autocad using this, thankfully just deleting areas and cutting out to make separate drawings.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
Re: How to use purebasic to operate autocad?
I see I made an error in the code I originally posted. I've posted a correction in the other thread but still with the caveat that I can't test this stuff out first.
Re: How to use purebasic to operate autocad?
Wow,this problem has been solved well finally!!! Thanks a lot for everyone,especially spikey。I tested his code by autocad 2007,and it worked well.
If you want to see details,pls see this link:
viewtopic.php?t=77343
And what's more,you should pay attention to the autocad's revison.( removing .16 is a selection)
Finally,there is a tiny mistake that missing the "IncludeFile "COMatePLUS.pbi".
Thanks again.
If you want to see details,pls see this link:
viewtopic.php?t=77343
And what's more,you should pay attention to the autocad's revison.( removing .16 is a selection)
Finally,there is a tiny mistake that missing the "IncludeFile "COMatePLUS.pbi".
Thanks again.