Jump to content
CADZealot

Running the lisp based on block name

Recommended Posts

CADZealot

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.

Share this post


Link to post
Share on other sites
Tharwat

Hi,

You can use instead the functions initget & getkword for a dynamic way.

Hit THIS LINK.

Share this post


Link to post
Share on other sites
CADZealot

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.

Share this post


Link to post
Share on other sites
Tharwat

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

 

Share this post


Link to post
Share on other sites
CADZealot

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")
  )

 

Share this post


Link to post
Share on other sites
Tharwat

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

 

Share this post


Link to post
Share on other sites
ronjonp
Posted (edited)

@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

Share this post


Link to post
Share on other sites
Tharwat

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. 

Share this post


Link to post
Share on other sites
CADZealot

Thank you so much Ron and Tharwat,

It's working perfectly now.

 

Thanks Again:celebrate:

Share this post


Link to post
Share on other sites
Tharwat
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. 

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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