Jump to content

Setting Variable from command line and using that variable in the command line


Recommended Posts

Posted

Alright so I'm pretty new to do doing this stuff on my own, but I started creating a routine to copy layouts and number the tabs according to some user input. I'm having 2 problems though, the program doesn't seem to work. I was able to get it to work when defining the variables as set and not requiring getstring to get them, and the second was that while that was going on I need to be able to set the "3-Duke" to increase, so ideally I'd be able to use the PGI variable within the command line as the actual number the variable is and not the letters themselves. I don't know how to do either of those things. 

 

#1. Allowing command to run with the getstring variables

 

#2 allowing the 3-Duke to be a variable that increases as the while statement runs.

 

 

(defun C:LYCP2 ( / pgi pgf)
(setq pgi (getstring T "\nEnter first page: ")
          pgf (getstring T "\nEnter final page: "))
(while (>= pgf pgi)
(setq pgi (1+ pgi)) 

   (command "_.layout" "c" "2-Duke" "3-Duke")

)
)

Posted
54 minutes ago, nj1105nj said:

Alright so I'm pretty new to do doing this stuff on my own, but I started creating a routine to copy layouts and number the tabs according to some user input. I'm having 2 problems though, the program doesn't seem to work. I was able to get it to work when defining the variables as set and not requiring getstring to get them, and the second was that while that was going on I need to be able to set the "3-Duke" to increase, so ideally I'd be able to use the PGI variable within the command line as the actual number the variable is and not the letters themselves. I don't know how to do either of those things. 

 

#1. Allowing command to run with the getstring variables

 

#2 allowing the 3-Duke to be a variable that increases as the while statement runs.

 

 

(defun C:LYCP2 ( / pgi pgf)
(setq pgi (getstring T "\nEnter first page: ")
          pgf (getstring T "\nEnter final page: "))
(while (>= pgf pgi)
(setq pgi (1+ pgi)) 

   (command "_.layout" "c" "2-Duke" "3-Duke")

)
)

Please Upload your sample dwg 

Posted
7 minutes ago, devitg said:

Please Upload your sample dwg 

 

I don't really have a sample drawing I guess. I have just been using a blank drawing template with the first layout being changed to "2-Duke" which is what I use at work. I can still upload it if there are some settings or something you might be able to see to discern if there is a problem. 

Posted (edited)

You have to change 3-duke inside the while You can read the 2-duke and get the 2 using a parse defun and set to X. Thats your homework the parse.lsp hint lee-mac.com.

 

(setq x (+ x 1))
(setq newtabname (strcat (rtos x 2 0) "-duke"))
(command "_.layout" "c" "2-Duke" newtabname)

 

Edited by BIGAL
Posted (edited)

So to my understanding, you're saying that I need a parse function to be able to convert the variable PGI into a numerical value, and then add that onto "-Duke" in order to create a new variable which to use to name the new tab?

 

I guess the only thing I'm confused by, is why can't I just replace the setq x into setq PGI and increase the value of PGI that way? Is it something to do with it being a user input? I'm also a bit confused as to what the rtos x 2 0 means, but I'm sure I can figure that out with some digging into that function. 

 

Edit:

 

So I think I'm understanding this a bit better. I'm unable to just add +1 to the PGI variable because it is a string and not a numeric variable. Is there a way for it to only accept numeric input so that I wouldn't have to parse it?

Edited by nj1105nj
Posted

See if this sheds some light:

(defun c:lycp2 (/ pgi pgf)
  (if (and (setq pgi (getint "\nEnter first page: ")) (setq pgf (getint "\nEnter final page: ")))
    (while (>= pgf pgi) (command "_.layout" "_N" (strcat (itoa pgi) "-Duke")) (setq pgi (1+ pgi)))
  )
  (princ)
)

 

Posted

It depends on how automated you want it, hence the hint about finding a number in a string. ronjonp has answered using your variable names rather than more generic example.

 

If your layouts are not x-DUKE then the pulling apart the layout name may be useful. For me it was D01 - Dxx etc so would want layout number 2 as you have and auto add "D". Or out of box "Layout"

Posted
On 7/13/2020 at 11:07 AM, ronjonp said:

See if this sheds some light:


(defun c:lycp2 (/ pgi pgf)
  (if (and (setq pgi (getint "\nEnter first page: ")) (setq pgf (getint "\nEnter final page: ")))
    (while (>= pgf pgi) (command "_.layout" "_N" (strcat (itoa pgi) "-Duke")) (setq pgi (1+ pgi)))
  )
  (princ)
)

 

Thank you for the code. I actually had come really close to figuring it all out and this got me the rest of the way there, much appreciated!

9 hours ago, BIGAL said:

It depends on how automated you want it, hence the hint about finding a number in a string. ronjonp has answered using your variable names rather than more generic example.

 

If your layouts are not x-DUKE then the pulling apart the layout name may be useful. For me it was D01 - Dxx etc so would want layout number 2 as you have and auto add "D". Or out of box "Layout"

I see. Starting to actually look more at the coding has really helped me to understand what is going on in other files I've downloaded. I think a few months ago this thread would have made no sense to me and now it at least makes a fair bit of sense. Thank you for all the help!

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