"command" shows all steps on a single line without carriage returns

"command" shows all steps on a single line without carriage returns

Gh_man
Advocate Advocate
1,578 Views
13 Replies
Message 1 of 14

"command" shows all steps on a single line without carriage returns

Gh_man
Advocate
Advocate

When I perform a command ("insert" for example) in AutoCAD, each step is shown on a separate line.

When I perform the same actions in a lisp, several of the commands are shown on a single line, which is hard to read.


---   Example (output using the command line):   ---
-insert
Enter block name or [?]: motor
Units: Unitless   Conversion:  1.000000
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: s
Specify scale factor for XYZ axes <1>:
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:
Specify rotation angle <0.00000000>:

---   Example (output using lisp):   ---
-insert Enter block name or [?] <motor roof>: h:/blocks/MOTOR.dwg
Units: Unitless   Conversion:  1.000000
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: s Specify scale factor for XYZ axes <1>: 1 Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:
Specify rotation angle <0.00000000>:

 

Note how in the second example, the insertion point and scale factor are all displayed on the same line, resulting in a confusing output. The carriage return after "insert" is also missing.

 

This is my lisp code:

 (command "-insert" "h:/blocks/MOTOR.dwg" "s" bs pause pause "")

 

"bs" is a previously defined variable.

0 Likes
1,579 Views
13 Replies
Replies (13)
Message 2 of 14

dbhunia
Advisor
Advisor

Hi

 

your line should be like........(let scale factor 1 and insertion point 0,0)

 

(command "-insert" "h:\\blocks\\MOTOR.dwg" "s" 1 "0,0" "")

What is "bs"??

 

And let scale factor 1, insertion point 0,0 and rotation 30 degree.....then

 

(command "-insert" "h:\\blocks/MOTOR.dwg" "s" 1 "0,0" 30)

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 3 of 14

cadffm
Consultant
Consultant

That wasn't the question, but i want to answer your question. BS is a symbol(lisp variable) and pointed to 1

So it is the value for the "s" = Scale option of -Insert command.

Sebastian

Message 4 of 14

Gh_man
Advocate
Advocate

your line should be like........(let scale factor 1 and insertion point 0,0)
(command "-insert" "h:\\blocks\\MOTOR.dwg" "s" 1 "0,0" "")

What is "bs"??


 

bs is a variable I created for "block scale factor". In this case, bs = 1, and is defined in some earlier code that I didn't show. The pauses are for user input (to select the co-ordinates), so that it's not tied to a specific location, ie., 0,0.

 

Using your example, I still get the output shown below: (text is all on a single line)

Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: s Specify scale factor for XYZ axes <1>: 1 Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: 0,0

 

0 Likes
Message 5 of 14

dbhunia
Advisor
Advisor

How far I know this is default behavior  using Lisp


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes
Message 6 of 14

ВeekeeCZ
Consultant
Consultant

@Gh_man wrote:

When I perform a command ("insert" for example) in AutoCAD, each step is shown on a separate line....


 

It's because YOU hit <enter>. Try to use the <spacebar> instead. 

 

And since we don't need <enter> within LISP... I really don't know how to mimic that...

The best I can do is this, but it's not good...

(progn (command "-insert" "test" "s") (princ "\n") (command  1 pause pause))

...or you can turn off the echo and print whatever prompt you want...

 

And @dbhunia is right, you have extra ""  at the end of the line.

0 Likes
Message 7 of 14

dgorsman
Consultant
Consultant

Your (command ...) arguments don't have any carriage returns either.  You might try submitting each argument as it's own (command ...) call.

 

For the most part you shouldn't be too concerned about how human-readable automation calls of this type are, with functionality being of primary importance.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 8 of 14

Gh_man
Advocate
Advocate

@@ВeekeeCZ wrote:

@Gh_man wrote:

When I perform a command ("insert" for example) in AutoCAD, each step is shown on a separate line....


 

It's because YOU hit <enter>. Try to use the <spacebar> instead. 

 

And since we don't need <enter> within LISP... I really don't know how to mimic that...

The best I can do is this, but it's not good...

(progn (command "-insert" "test" "s") (princ "\n") (command  1 pause pause))

...or you can turn off the echo and print whatever prompt you want...

 

And @dbhunia is right, you have extra ""  at the end of the line.


 

That is indeed the difficulty. In AutoCAD, I can choose to use an <enter> instead of a <space>, but I can't think of a way to duplicate that in a lisp. I could turn off the echo, but I want the user to be able to see the steps, so that if something goes wrong, they can trace it back to the error.

 

Your example code looks good, but for some reason the \n newline character has no effect. I suspect that CAD doesn't accept new commands in the middle of a currently executing command. I also tried invoking the \n transparently, but also without success.

 

The extra "" is necessary because my block has an attribute; the "" accepts its default value.

0 Likes
Message 9 of 14

Gh_man
Advocate
Advocate

@dgorsman wrote:

Your (command ...) arguments don't have any carriage returns either.  You might try submitting each argument as it's own (command ...) call.

 

For the most part you shouldn't be too concerned about how human-readable automation calls of this type are, with functionality being of primary importance.


 

Multiple (command ...) arguements  sounds like a good option, but it didn't work in testing.

 

Human readability is necessary because the lisp pauses for user input, and the instruction for the user input ends up preceded with a long string that's hard to read. This problem is actually worse than seen here, because I've only posted a single fairly simple lisp, but there are more complex ones with the same issue.

0 Likes
Message 10 of 14

ВeekeeCZ
Consultant
Consultant

@Gh_man wrote:

That is indeed the difficulty. In AutoCAD, I can choose to use an <enter> instead of a <space> That was meant just as way to confirm you that both autocad's a and lisp's versions are the same, with no predefined new line character.

but I can't think of a way to duplicate that in a lisp. Me neither. I could turn off the echo, but I want the user to be able to see the steps, so that if something goes wrong, they can trace it back to the error. Sure, that makes sence.

 

Your example code looks good, but for some reason the \n newline character has no effect. I suspect that CAD doesn't accept new commands in the middle of a currently executing command. I also tried invoking the \n transparently, but also without success.


 

It does. See my command-line listing. But in a bad position, and no way to get that where we want to have it.

 

Command: (progn (command "-insert" "test" "s") (princ "\n") (command  1 pause pause))
-insert Enter block name or [?] <test>: test
Units: Millimeters   Conversion:    1.0000
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]: s Specify scale factor for XYZ axes <1>:
1 Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:
Specify rotation angle <0>:
Command: nil
Message 11 of 14

dgorsman
Consultant
Consultant

Don't pause in the middle of calling AutoCAD commands for user input - use (getkword ...), (getstring ...) and other functions to get that information in a structured fashion first so users don't have to wade through extra feedback.  That also allows you to validate each input and perform any extra logic prior to use.  Then you can feed all the results to the command line later.

 

Also have a look at skipping command-line calls altogether.  For example, when inserting blocks you could keep the (command ...) call for insert but switch off the system variable that prompts for attributes.  Change the attribute values through code after insert (which will also allow for handling problems like attributes missing or out-of-sequence).  You could also skip the (command ...) call for inserting and do that through code as well.  It's a good place to start getting a bit deeper into LISP coding.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


0 Likes
Message 12 of 14

ВeekeeCZ
Consultant
Consultant

Possibly...?!

 

(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "-insert\rtest\rscale\r1\r"))

 

Also found THIS old thread same info. I bed that @john.uhden would want to add some actual thoughts on this one.

Message 13 of 14

Gh_man
Advocate
Advocate

@@ВeekeeCZ wrote:

Possibly...?!

 

(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "-insert\rtest\rscale\r1\r"))

 

Also found THIS old thread same info. I bed that @john.uhden would want to add some actual thoughts on this one.


 

This looks promising! I'm new to the VLA world, but in preliminary tests this seems to mostly do what I want. The main thing I'm struggling with using the VLA method is getting the code to pause for user input. (The block rotation is done by the user.)

 

Haven't had time to read the prior thread, but hopefully will get a chance tomorrow. Thanks!

0 Likes
Message 14 of 14

scot-65
Advisor
Advisor
dgorsman, in my opinion, is pointing you in the right direction.
Gather and test if valid user input before executing. This means
avoiding 'pause'.

I will add the following regarding an attributed block:
Run the -insert command as if there are no attributes.

If there *might* be an attribute, then provide a command suffix as follows:
(if (> (getvar 'CMDACTIVE) 0) (command "ValueOfAttribute"))

When there *might* be more than one attribute, loop it inside a FOREACH:
(foreach x (list "Value1" "Value2" "Value3")
(if (> (getvar 'CMDACTIVE) 0) (command x))
);foreach

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes