Jump to content

Recommended Posts

Posted

Hello, i'm verry noob with lisp and i have a simple question.

 

i know its easy to call a lisp function inside acad when they include something like defun:

but how do i call a function when the structure is like this

 

Option Explicit

 

Public Sub Main()

code here code here code here

code here code here code here

code here code here code here

End Sub

Posted

Calling functions is pretty much the same no matter what, the only difference I've really come across is whether it's a command or a function. The only difference is whether or not it's preceeded by a c:, like so:

 

; Command
(defun c:dothis()
 (princ "hello world")
)

; Function
(defun dothisalso()
 (princ "What's up?")
)

I hope that answers your question, if not, I could try again ^^'

Posted

Im not sure how do i call this code inside autoCAD ... do i need to add a function inside the code?

 

Option Explicit

Public Sub Main()
   Dim objBlock As AcadBlockReference
   Dim objEnt As AcadEntity
   Dim colHyps As AcadHyperlinks
   Dim fso As FileSystemObject
   
   Set fso = New FileSystemObject
   
   For Each objEnt In ThisDrawing.ModelSpace
       If TypeOf objEnt Is AcadBlockReference Then
           Set objBlock = objEnt
           Set colHyps = objBlock.Hyperlinks
           On Error Resume Next ' In case we encounter any blocks that DON'T have hyperlinks
           fso.CopyFile colHyps.Item(0).URL, "E:\Temp\"  ' replace E:\Temp\ with your project directory
       End If
   Next objEnt
   
   Set fso = Nothing
End Sub

Posted
Calling functions is pretty much the same no matter what, the only difference I've really come across is whether it's a command or a function. The only difference is whether or not it's preceeded by a c:, like so:

 

; Command
(defun c:dothis()
 (princ "hello world")
)

; Function
(defun dothisalso()
 (princ "What's up?")
)

I hope that answers your question, if not, I could try again ^^'

 

what he appears to be asking is how to call a vba routine inside cad. and im quite new to vba and the only way i personally know how to run those is through 'vbaide' or 'vbarun'

Posted

Not working i tried

 

(defun c:dothis()
Option Explicit

Public Sub Main()
   Dim objBlock As AcadBlockReference
   Dim objEnt As AcadEntity
   Dim colHyps As AcadHyperlinks
   Dim fso As FileSystemObject
   
   Set fso = New FileSystemObject
   
   For Each objEnt In ThisDrawing.ModelSpace
       If TypeOf objEnt Is AcadBlockReference Then
           Set objBlock = objEnt
           Set colHyps = objBlock.Hyperlinks
           On Error Resume Next ' In case we encounter any blocks that DON'T have hyperlinks
           fso.CopyFile colHyps.Item(0).URL, "E:\Temp\"  ' replace E:\Temp\ with your project directory
       End If
   Next objEnt
   
   Set fso = Nothing
End Sub
)

and

 

 

(defun c:dothis()
   Dim objBlock As AcadBlockReference
   Dim objEnt As AcadEntity
   Dim colHyps As AcadHyperlinks
   Dim fso As FileSystemObject
   
   Set fso = New FileSystemObject
   
   For Each objEnt In ThisDrawing.ModelSpace
       If TypeOf objEnt Is AcadBlockReference Then
           Set objBlock = objEnt
           Set colHyps = objBlock.Hyperlinks
           On Error Resume Next ' In case we encounter any blocks that DON'T have hyperlinks
           fso.CopyFile colHyps.Item(0).URL, "E:\Temp\"  ' replace E:\Temp\ with your project directory
       End If
   Next objEnt
   
   Set fso = Nothing
End Sub
)

any other idea?

Posted

You are mixing up LISP with VBA - two very different things :geek:

Posted

how do i call this function...

this is only what i want to know

 

PLEASE

Posted

you should have that file saved as a .dvb so you can make a lisp that looks like this

 

[color=Black][color=#383838](defun c:LoadMacro ()
(setvar "filedia" 0);//To avoid the VBALOAD dialog box display
(command "_VBALOAD" "c:\\temp\\macro.dvb");<--- change to your vba file
(setvar "filedia" 1);//Reset filedia to 1
(command "_-VBARUN" "macro1");//- To avoid the VBARUN dialog box display
)[/color][/color]

 

reference : http://usa.autodesk.com/adsk/servlet/ps/item?siteID=123112&id=2888989&linkID=9240617

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...