Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

open command in script using a variable

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
gcsjlewis
2006 Views, 10 Replies

open command in script using a variable

**Using Autocad Electrical 2011

So here is what i have come up with:

 

I have 4 lisps, all saved in one file (new_project.lsp)...Not very original but i am just testing

I have them called out as 

(defun 120VAC () (my lisp))

(defun 120VAC2 () (my lisp))

(defun 120to24 () (my lisp))

(defun 24vdc2 () (my lisp))

 

I created a macro calling a script file that i created for each lisp.

 

^C^C_.script;"t:/acad_autolisps/scripts/New_Project_Scripts/120VAC_Incoming.scr"
^C^C_.script;"t:/acad_autolisps/scripts/New_Project_Scripts/120VAC_Second.scr"
^C^C_.script;"t:/acad_autolisps/scripts/New_Project_Scripts/120VAC_to_24VDC.scr"
^C^C_.script;"t:/acad_autolisps/scripts/New_Project_Scripts/24VDC_Second.scr"

 

Everything works great. other than one thing.

 

In my script file I have the following setup:

 

filedia 0
_.open "t:\acad_autolisps\testing\test_project\000-00-07.dwg"
(load "new_project.lsp" nil)
(if 120vac (120vac))

 

My question is, is there a way to open a file in a script using a variable i set using the following command

 

(setq dwgname (car (c:wd_proj_getdwgnam (ace_getactiveproject) 6 0)))

 

I tried _.open dwgname...but this doesn't work,

 

I can also put in

 

 (car (c:wd_proj_getdwgnam (ace_getactiveproject) 6 1)) which if i typed this into the command line it will open the 7th drawing in the project.

 

Iv'e tried a bunch of various ways that will open the drawing through the command line but not through script.

 

any ideas on how to make this work??

10 REPLIES 10
Message 2 of 11
hmsilva
in reply to: gcsjlewis

EDITED
was a bad idea
deleted... Smiley Embarassed

 

Henrique

EESignature

Message 3 of 11
gcsjlewis
in reply to: hmsilva

I tired messing around with that too.
This is what I get:

Command: (vl-string-translate "\\" "\"" (car (c:wd_proj_getdwgnam
(ace_getactiveproject) 6 0)))
"T:\"Acad_Autolisps\"Testing\"Test_project\"000-00-07.dwg"


I also tried this before
(setq dwgname (car (c:wd_proj_getdwgnam (ace_getactiveproject) 6 0 )))
(vl-string-translate "\\" "\"" dwgname)
Result
Command: (vl-string-translate "\\" "\"" dwgname)
; error: bad argument type: (or stringp symbolp): nil
Or:
(vl-string-translate "\\" "\"" (read dwgname))
Command: (vl-string-translate "\\" "\"" (read dwgname))
; error: bad argument type: (or stringp symbolp): nil

________________________________
The information contained in this message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately, and delete the original message.
Message 4 of 11
bhull1985
in reply to: gcsjlewis

Try messing around with this:

(Defun c:foo ()
      (startapp
            (strcat "explorer /select, "
                    (getvar "dwgprefix")
                    (getvar "dwgname")
                    ", /e"))
)

 and this:

 

(strcat (getvar "dwgprefix")(getvar "dwgname")) 

 HTH

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 5 of 11
gcsjlewis
in reply to: bhull1985

I cannot get this too work without opening another session of autocad, and I do not want that to happen because then it doesn't recognize my (car (c:wd_proj_getdwgnam (ace_getactiveproject) 6 0)) command

________________________________
The information contained in this message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately, and delete the original message.
Message 6 of 11
hmsilva
in reply to: gcsjlewis

Try

 

(vl-string-translate "/" "\\"" (car (c:wd_proj_getdwgnam (ace_getactiveproject) 6 0)))

 

should work...

 

HTH

Henrique

EESignature

Message 7 of 11
gcsjlewis
in reply to: hmsilva

This doesn't work either.... Here are my results


Command: (vl-string-translate "/" "\\"" (car (c:wd_proj_getdwgnam
(ace_getactiveproject) 6 0)))
("_>
("_> *Cancel*
; error: Function cancelled

________________________________
The information contained in this message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately, and delete the original message.
Message 8 of 11
hmsilva
in reply to: gcsjlewis


@gcsjlewis wrote:
This doesn't work either.... Here are my results

Command: (vl-string-translate "/" "\\"" (car (c:wd_proj_getdwgnam
(ace_getactiveproject) 6 0)))
("_>
("_> *Cancel*
; error: Function cancelled
...

First of all, sorry manamalewis, I couldn't test it and and had a typo...

what I had thought was

(vl-string-translate "\\" "/" (car (c:wd_proj_getdwgnam (ace_getactiveproject) 6 0)))

at the command line I think it works, in a .scr file, I don't know because at the moment I am out of the office and can't test ...

 

Henrique

EESignature

Message 9 of 11
hmsilva
in reply to: gcsjlewis

Not the answer you expect, but can be a work around

Untested...

(defun c:MyScr (/ DWGNAME SCR SCRFILE)
  (if (setq dwgname (car (c:wd_proj_getdwgnam (ace_getactiveproject) 6 0)))
    (progn
      (setq scrfile "C:\\Windows\\temp\\MyScr.scr")
      (setq scr (open scrfile "w"))
      (write-line (strcat "filedia\n0") scr)
      (write-line (strcat "_open\n\"" dwgname "\"") scr)
      (write-line "(load \"new_project.lsp\" nil)" scr)
      (write-line "(if 120vac (120vac))" scr)
      (close scr)
      (command "_.SCRIPT" scrfile)
    );; progn
  );; if
  (princ)
);; MyScrcr

HTH

Henrique

EESignature

Message 10 of 11
gcsjlewis
in reply to: gcsjlewis

AWESOME!!! Thanks, I had to modify my lisp/script/macros alittle bit, but it works.  I've read multiple times and places that user input cannot be used across different drawings and using different lisps all rolled into one project but this little bit of code that you did for me solved that problem...  Thanks again

Message 11 of 11
hmsilva
in reply to: gcsjlewis

You're welcome!


Glad I could help

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost