Welcome to Dream.In.Code
Become a VB Expert!

Join 137,266 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,505 people online right now. Registration is fast and FREE... Join Now!




Interacting with autocad using Vb6.0 ActiveX DLL

 
Reply to this topicStart new topic

Interacting with autocad using Vb6.0 ActiveX DLL

Rating  5
nvalwaikar
26 Nov, 2006 - 09:26 PM
Post #1

New D.I.C Head
*

Joined: 26 Nov, 2006
Posts: 2


My Contributions
If i am Creating a VB6.0 standard exe than i have to connect to autocad using the below code

Public acadApp As AcadApplication

Private Sub Form_Load()
frmStatus.Show

If ConnectToAutoCad = False Then
MsgBox "Unable to Connect to Autocad", vbCritical
End
End If

Public Sub ConnecttoAutocad ()
On Local Error Resume Next
Set acadApp = Nothing

''' Try to Connect to AutoCad2004
If acadApp Is Nothing Then
Set acadApp = GetObject(, "AutoCAD.Application.16")
If Err Then
Err.Clear
Set acadApp = CreateObject("AutoCAD.Application.16")
End If
End If
end Sub

the above code works fine as long as i am working on single autocad session and in a single active dwg
but if there are multiple autocad sessions running then it fails to connect to the autocad session that i want....
an alternative i was thinking of was to create a activeX dll wrapper which would be called from within the autocad

For eg. like this
1) (setq acd (vlax-get-acad-object)) ;; Get Acad Object
2) (setq srv (vlax-invoke acd "getinterfaceobject" "MyCadDll.MyTestProject")) ;; Initialize My Wrapper Dll
3) (setq ret (vlax-invoke srv "ChangeAllTextColorToRed" )) ;; Call my Function Present in the Dll

In this dll there is a Public function called 'ChangeAllTextColorToRed' which when invoked
from Visual-Lisp within autocad as shown in Step3 the all the text color present in the dwg should be changed to Red.

If this function was to be done in standard exe it would have been like this...

Public Function ChangeAllTextColorToRed()
Dim Ent As AcadEntity
For Each Ent In acadApp.ActiveDocument.ModelSpace
Ent.TrueColor = vbRed
Next Ent
End Function

this function works in standard exe coz in form load i have created the AcadApp object
which is an instance of current acad application, i want to create the same function in a activeX dll...



User is offlineProfile CardPM
+Quote Post

eXceed69
RE: Interacting With Autocad Using Vb6.0 ActiveX DLL
27 Nov, 2006 - 01:15 AM
Post #2

"Super Sentai Knight Of DawN"
Group Icon

Joined: 12 Nov, 2006
Posts: 682



Thanked: 1 times
Dream Kudos: 675
My Contributions
Here some link

Autocad linking to VB Dll

other one
User is offlineProfile CardPM
+Quote Post

EMMADDAI
RE: Interacting With Autocad Using Vb6.0 ActiveX DLL
24 Jul, 2008 - 02:08 AM
Post #3

New D.I.C Head
*

Joined: 15 Nov, 2006
Posts: 7


My Contributions
hI thanks for the help you gave me.
Anyway, am still struggling to make it work in my application
Could you or anyone help me plot coordinates (XYZ) of points by just clicking a button in a vb.net application, and save points in a dxf or .dwg file, without necessarily opening autocad?
thanks.

QUOTE(nvalwaikar @ 26 Nov, 2006 - 10:26 PM) *

If i am Creating a VB6.0 standard exe than i have to connect to autocad using the below code

Public acadApp As AcadApplication

Private Sub Form_Load()
frmStatus.Show

If ConnectToAutoCad = False Then
MsgBox "Unable to Connect to Autocad", vbCritical
End
End If

Public Sub ConnecttoAutocad ()
On Local Error Resume Next
Set acadApp = Nothing

''' Try to Connect to AutoCad2004
If acadApp Is Nothing Then
Set acadApp = GetObject(, "AutoCAD.Application.16")
If Err Then
Err.Clear
Set acadApp = CreateObject("AutoCAD.Application.16")
End If
End If
end Sub

the above code works fine as long as i am working on single autocad session and in a single active dwg
but if there are multiple autocad sessions running then it fails to connect to the autocad session that i want....
an alternative i was thinking of was to create a activeX dll wrapper which would be called from within the autocad

For eg. like this
1) (setq acd (vlax-get-acad-object)) ;; Get Acad Object
2) (setq srv (vlax-invoke acd "getinterfaceobject" "MyCadDll.MyTestProject")) ;; Initialize My Wrapper Dll
3) (setq ret (vlax-invoke srv "ChangeAllTextColorToRed" )) ;; Call my Function Present in the Dll

In this dll there is a Public function called 'ChangeAllTextColorToRed' which when invoked
from Visual-Lisp within autocad as shown in Step3 the all the text color present in the dwg should be changed to Red.

If this function was to be done in standard exe it would have been like this...

Public Function ChangeAllTextColorToRed()
Dim Ent As AcadEntity
For Each Ent In acadApp.ActiveDocument.ModelSpace
Ent.TrueColor = vbRed
Next Ent
End Function

this function works in standard exe coz in form load i have created the AcadApp object
which is an instance of current acad application, i want to create the same function in a activeX dll...


User is offlineProfile CardPM
+Quote Post

EMMADDAI
RE: Interacting With Autocad Using Vb6.0 ActiveX DLL
25 Jul, 2008 - 08:44 AM
Post #4

New D.I.C Head
*

Joined: 15 Nov, 2006
Posts: 7


My Contributions
hI thanks for the help you gave me.
Anyway, am still struggling to make it work in my application
Could you or anyone help me plot coordinates (XYZ) of points by just clicking a button in a vb.net application, and save points in a dxf or .dwg file, without necessarily opening autocad?
thanks.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 07:30PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month