calling predefined lisp commands in another lisp

calling predefined lisp commands in another lisp

Yamishon_Noah
Enthusiast Enthusiast
7,964 Views
30 Replies
Message 1 of 31

calling predefined lisp commands in another lisp

Yamishon_Noah
Enthusiast
Enthusiast

Hi

 

I'm writing LISP like this below

 

(defun c:mk ()
(command "_3dpoly" "100,100,0" "250,250,0" "250,250,750" "")

(princ)
)

 

I want to call another lisp command ATTACHTAG, I wrote like below

 

(defun c:mk ()
(command "_3dpoly" "100,100,0" "250,250,0" "250,250,750" "")

(c:ATTACHTAG)

(princ)
)

 

Command executes but it asks to select object (which commands purpose) 

 

     command: ATTACHTAG 

          --> Select object: [I have to select the 3D polyline]

          --> Enter TAG name: [I have to enter name for it]

 

How can I write further above steps in my LISP?

 

pls help

0 Likes
Accepted solutions (2)
7,965 Views
30 Replies
Replies (30)
Message 2 of 31

ВeekeeCZ
Consultant
Consultant
You won't. Is is lsp or vlx? You need to rewrite the attachtag to make a call up function and the main function.

(defun attachtag (ss tagname / ...) ...)
0 Likes
Message 3 of 31

Yamishon_Noah
Enthusiast
Enthusiast

Hi

 

ATTACHTAG is available in FAS file 

 

how can I re write this..!!!

0 Likes
Message 4 of 31

ВeekeeCZ
Consultant
Consultant

You won't. But the developer can, ask him!

 

Anyway, does the routine something special? It sounds like you can find a tun of others on web... 

0 Likes
Message 5 of 31

Yamishon_Noah
Enthusiast
Enthusiast

Hi..

 

yeah I could not find that routing in web (searched lot)

 

I cant contact author - unknown

 

actually it applies TAG to drawn 3Dpolyline

 

       Consider here 3Dpolyline as cable and TAG as cable name.

 

Also, that FAS has capability to extract TAG, 3Dpolyline length etc.

 

My doubt is, if we can call command of another lisp why cant we give sub functions of it?

 

REALLY NOT POSSIBLE????

 

please

0 Likes
Message 6 of 31

ВeekeeCZ
Consultant
Consultant

Structuring the code into call up and main function is common practice, so maybe the developer made it that way... 

 

Anyway, for supplying the selection set you can try this trick...

 

 

(defun c:test ()
  (setq ss (ssget))
  (sssetfirst nil ss)
  (c:test2))

(defun c:test2 ()
  (setq ss1 (ssget))
  (sslength ss1))


; for the macro:

(defun c:test3 ()
  (setq tag1 (getstring "\nEnter tag name: "))
  (setq tag2 (getstring "\nEnter 2nd tag name: "))
  (princ (strcat "\ntag1: " tag1 ", tag2: " tag2 ", tag3: " *test3-tag*))
  (princ)
)
  
(setq *test3-tag* "tag-set-using-global-variable")

 

Or you can use a button macro.

 

test3;tg1;tg2;

 

Message 7 of 31

stevor
Collaborator
Collaborator
Or, using the method of ' c:test3' to write a script file each time.
S
0 Likes
Message 8 of 31

ВeekeeCZ
Consultant
Consultant

@ВeekeeCZ wrote:

 

...

  

...
; for the macro:

(defun c:test3 ()
  (setq tag1 (getstring "\nEnter tag name: "))
  (setq tag2 (getstring "\nEnter 2nd tag name: "))
  (princ (strcat "\ntag1: " tag1 ", tag2: " tag2 ", tag3: " *test3-tag*))
  (princ)
)
  
(setq *test3-tag* "tag-set-using-global-variable")

 

Or you can use a button macro.

 

test3;tg1;tg2;

 

Not sure if this method helps. I was hoping that we can evaluate variables somehow - using DIESEL at least... but I'm unable to make it work 😞 Only you can use in macro for LISP's (getstring) is a plain text.

 

$(eval,users1) does not work 😞

0 Likes
Message 9 of 31

john.uhden
Mentor
Mentor

Beekee:

 

Maybe he can use (vlax-add-cmd ...) so that he can feed the function its input via the command function.

John F. Uhden

0 Likes
Message 10 of 31

Yamishon_Noah
Enthusiast
Enthusiast

Beekee...

 

Thank you very much for your effort..

 

 

you find that lisp I want to call in, Totallength.rar 

 

kindly let me know if any possibilities...

 

 

thanks

0 Likes
Message 11 of 31

ВeekeeCZ
Consultant
Consultant

Never mind. See the @hmsilva's solution.

 

Thanks Henrique for your contribution! Still have a lot to learn 🙂

Message 12 of 31

hmsilva
Mentor
Mentor

@thegreatkarthik67 wrote:

Hi

 

I'm writing LISP like this below

 

(defun c:mk ()
(command "_3dpoly" "100,100,0" "250,250,0" "250,250,750" "")

(princ)
)

 

I want to call another lisp command ATTACHTAG, I wrote like below

 

(defun c:mk ()
(command "_3dpoly" "100,100,0" "250,250,0" "250,250,750" "")

(c:ATTACHTAG)

(princ)
)

 

Command executes but it asks to select object (which commands purpose) 

 

     command: ATTACHTAG 

          --> Select object: [I have to select the 3D polyline]

          --> Enter TAG name: [I have to enter name for it]

 

How can I write further above steps in my LISP?

 

pls help


Try

(vl-load-com)
(defun c:mk ( / tag)
    (command "_3dpoly" "100,100,0" "250,250,0" "250,250,750" "")
    (setq tag (getstring "\nEnter TAG: "))
    (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "ATTACHTAG\r_L\r\r" tag "\r"))
(princ)
)

 

 

Hope this helps,
Henrique

EESignature

Message 13 of 31

Yamishon_Noah
Enthusiast
Enthusiast

Hi Henrique,

 

first Thank you,

 

I ran your lisp, it need one more step I think

 

it executes,

*3D polyline created-----------------OK

*attachtag command executed---OK

*Selected last entity------------------OK

 

 

but it asks Enter TAG: see below pic

 

Enter TAG.JPGhere I want to put tag name. For example: cable1

how can I add this in the lisp???

 

 

if its done lisp is ready for my use..

 

Thanks

0 Likes
Message 14 of 31

hmsilva
Mentor
Mentor
Accepted solution

Enter TAG: cable1

 

if harcoded

 

(vl-load-com)
(defun c:mk ( / tag)
    (command "_3dpoly" "100,100,0" "250,250,0" "250,250,750" "")
    (setq tag "cable1")
    (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "ATTACHTAG\r_L\r\r" tag "\r"))
(princ)
)

 

Hope this helps,
Henrique

EESignature

Message 15 of 31

ВeekeeCZ
Consultant
Consultant
Accepted solution

..

(vl-load-com)
(defun c:mk ( / tag)
    (command "_3dpoly" "100,100,0" "250,250,0" "250,250,750" "")
    (setq tag (getstring "\nEnter TAG: "))
    (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "ATTACHTAG\r_L\r\r" tag "\r"))
(princ)
)

 

It's about the bold line. If you don't wanna the user prompt, then set the constant - it was just an example.

 

(setq tag "cable1")

Message 16 of 31

Yamishon_Noah
Enthusiast
Enthusiast

Thank you @hmsilva @ВeekeeCZ

Great... Smiley Very Happy

0 Likes
Message 17 of 31

hmsilva
Mentor
Mentor

You're welcome!  Smiley Happy

Henrique

EESignature

0 Likes
Message 18 of 31

Yamishon_Noah
Enthusiast
Enthusiast

@hmsilva@ВeekeeCZ

 

hi ,

 

 

need your help last time..

 

I wrote lisp for 2 3D polyline as below

 

(vl-load-com)
(defun c:mk ( / tag)
(command "_3dpoly" "177574.2378,6549.4066,4500" "177574.2378,6549.4066,1500" "177574.2378,-1053.4106,1500" "190716.7369,-1053.4106,1500" "190716.7369,-1053.4106,-1500" "")
(setq tag "cable 1")
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "ATTACHTAG\r_L\r\r" tag "\r"))

(command "_3dpoly" "179804.6792,6570.2396,4500" "179804.6792,6570.2396,1500" "179804.6792,-1053.4106,1500" "190716.7369,-1053.4106,1500" "")
(setq tag "cable 2")
(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "ATTACHTAG\r_L\r\r" tag "\r"))
(princ)
)


TAG can be added to only last drawn 3D polyline i.e.cable 2, cable 1 tag not added to first 3D polyline


I think 3D polyline command executes first and TAG second...

 

I want to create 3D polyline then add Tag to it then another 3D polyline then tag to it.. like many 3Dpolylines to be drawn...

 

Kindly help me pls...

 

 

 

0 Likes
Message 19 of 31

hmsilva
Mentor
Mentor

vla-sendcommand will run after the lisp ends...

 

The tags from your sample are XDATA and the APPID is Ishwinder_LineTag.

Try...

(defun c:mk ( / tag)
    (if (not (tblsearch "APPID" "Ishwinder_LineTag"))
            (regapp "Ishwinder_LineTag")
        )
    (defun tag (name)
        (entmod (append (entget (entlast)) (list (list -3 (list "Ishwinder_LineTag" '(1002 . "{") (cons 1000  name) '(1002 . "}"))))))
    )
(command "_3dpoly" "177574.2378,6549.4066,4500" "177574.2378,6549.4066,1500" "177574.2378,-1053.4106,1500" "190716.7369,-1053.4106,1500" "190716.7369,-1053.4106,-1500" "")
(tag "cable 1")
(command "_3dpoly" "179804.6792,6570.2396,4500" "179804.6792,6570.2396,1500" "179804.6792,-1053.4106,1500" "190716.7369,-1053.4106,1500" "")
(tag "cable 2")
(princ)
)

 

Hope this helps,
Henrique

EESignature

Message 20 of 31

Yamishon_Noah
Enthusiast
Enthusiast

Smiley Very Happy Smiley Very Happy Smiley Very Happy 

 

it works perfectly 

 

@hmsilva great... thanks a ton

 

but I'm facing different problem now.. 3D polylines not drawn in proper coordinates entered see below pictures..

 

I wrote this,

 

(defun c:mk ( / tag)
    (if (not (tblsearch "APPID" "Ishwinder_LineTag"))
            (regapp "Ishwinder_LineTag")
        )
    (defun tag (name)
        (entmod (append (entget (entlast)) (list (list -3 (list "Ishwinder_LineTag" '(1002 . "{") (cons 1000  name) '(1002 . "}"))))))
    )
(command "_3dpoly" "177574,6549,4500" "177574,6549,1500" "177574,-1053,1500" "190716,-1053,1500" "190716,-1053,-1500" "")
(tag "cable 1")

  
(princ)
)

 

3Dpolyline vertex placement is wrong every time I run this lisp

 

I ran this lisp in TOP VIEW

top1.JPGTop2.JPG

  

 

I changed coordinates I tried many times...

 

everytime AutoCAD draws 3D polyline differently. [Not in given coordinates]

 

I attached cad file for your reference.

 

pls help... because LISP is ready for use

 

this I ran this lisp in ISO VIEW

3d.JPG3d2.JPGpls help.

 

 

 

 

 

0 Likes