Jump to content

Running the lisp based on block name


CADZealot

Recommended Posts

Hi Everyone,

I have a three lisp to create layouts automatically for three different sheet size. (A1,A2 & A3). Right now I'm running the lisp separately for required sheet size. Instead of that can we run the lisp based on block name which i inserted for layout creation.

For Ex. If i inserted A2 block, then lisp will check the block availability (A1,A2 & A3) A2 is available now...so lisp for creating A2 sheet should be run.

 

Thanks in advance.

Link to comment
Share on other sites

Hi Tharwat,

Using that we can run the lisp from the options..but in that case we need to select the lisp based on inserted block.

Is there any other way to run the lisp automatically by available block name.

 

 

Thanks.

Link to comment
Share on other sites

What I meant with my previous reply is that you can have one program asks the user about the block name then insert it if that block name is existed into the same drawing otherwise an alert message to inform the user is that the block name is not available.

 

(initget "A1 A2 A3")
(setq blk (getkword "\nSpecify block name to insert [A1,A2,A3:"))
(if (tblsearch "BLOCK" blk)
   ;;; then your stuff here to insert the desire block name once its available in drawing.
   ;; else alert a message to user.
  )

 

Link to comment
Share on other sites

Thanks for the Explanation,

I have checked that but i don't know exactly that how to modify that. could you please help me on this.

(defun c:123(/)
 (initget "A1 A2 A3")
(setq blk (getkword "\nSpecify block name to insert [A1,A2,A3]:"))
(if (tblsearch "BLOCK" blk)
 (C:A1)
  (C:A2)
  (C:A3)
   ;;; then your stuff here to insert the desire block name once its available in drawing.
   ;; else alert a message to user.
  ;(alert "Hi")
  )
  )


(defun c:A1 (/)
  (alert "A1 Here")
  )
(defun c:A2 (/)
  (alert "A2 Here")
  )

(defun c:A3 (/)
  (alert "A3 Here")
  )

 

Link to comment
Share on other sites

Give this a go and let me know.

(defun c:Test (/ blk)
  (initget "A1 A2 A3")
  (and (setq blk (getkword "\nSpecify block name to insert [A1,A2,A3]:"))
       (or (tblsearch "BLOCK" blk)
           (alert (strcat "Block name < "
                          blk
                          " > was not found in this drawing."
                  )
           )
       )
       (eval (nth (vl-position blk '("A1" "A2" "A3"))
                  '((c:A1) (c:A2) (c:A3))
             )
       )
  )
  (princ)
)

 

Link to comment
Share on other sites

@Tharwat

I did not read this whole thread but FWIW .. you could shorten up your eval code like so:

(eval (read (strcat "(c:" blk ")")))

 

Edited by ronjonp
Link to comment
Share on other sites

Thanks Ron for your important note. :) 

Although that I recommended the OP just to have these three routines as one but apparently they have their reason to go with one. 

Link to comment
Share on other sites

9 hours ago, CADZealot said:

Thank you so much Ron and Tharwat,

It's working perfectly now.

 

Thanks Again:celebrate:

Good to hear that. :D 

You're welcome anytime. 

Link to comment
Share on other sites

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