Jump to content

Ssyntaxis to add subroutines from a self developed Lisp program


Recommended Posts

Posted

Hello everyone,

 

I developed a routine that updates blocks from a specific folder on the server as follows:

 

Command: UBV
Update selected blocks or all of them? [Selection/All/Name]:

 

I want to specify a name for many drawings for all to update the same block.

I know I can run the command like this:

(c:UBV)

But I want to add the subroutines
"N" (for the name variable)
"BlockName" (for the block name)

 

Since this is a command that I developed, I cannot run it like this:

(command
  "UBV"
  "n"
  "BlocknName"
)

Because it is not an AutoCAD command. My question is:

Can I run a self developed command (c:UBV) adding subroutines?
 
  My first guess was something like but it didin't work.
 

(C:UBV "n" "BlockName")

 

 

What would be the syntaxis to add subroutines from a self developed Lisp program?

 

Thanks in advance

Posted (edited)

You basically don't. That's why other programmers such as our legend Lee Mac do something like this: Outline Objects

 

Notice he created another function (LM:outline) that accepts an argument. In your case, you'd want to build a function that accepts 2 arguments, and then call the function. He then created the function (c:outline) and in that, he call the function LM:outline.

 

I do use LM:outline too for other purposes and because LM:outline returns a selection set, I can then use it to do other stuff with it on other functions.

 

The purpose of this is so that you can do something like what you're encountering now and gives more flexibility for users to modify any variables to suit their needs:

 

(defun ubv (arg1 arg2 / )
    ;; your codes
    ;; Better have your function return something so that you can use the return values for something else outside it.
    )


(defun c:ubv nil (ubv "n" "Block Name"))
(defun c:ubv2 nil (ubv "n2" "Block Name 2"))
(defun c:ubvp nil (ubv (getstring t "\nSpecify name for drawing: ") (getstring t "\nSpecify block name: ")))

;; and so on

 

Edited by Jonathan Handojo
Posted
(defun c:ubv1 ( / )
  (vl-load-com)
  (vla-sendcommand
    (vla-get-activedocument
      (vlax-get-acad-object)
    )
    "UBV n BlockName "
  )
  (princ)
)

 

  • Thanks 1
Posted
On 7/24/2020 at 10:26 PM, Stefan BMR said:

(defun c:ubv1 ( / )
  (vl-load-com)
  (vla-sendcommand
    (vla-get-activedocument
      (vlax-get-acad-object)
    )
    "UBV n BlockName "
  )
  (princ)
)

 

Wonderful Stefan. Thanks a lot. There is always who has an answer.

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...