Jump to content

Changing Commands in a Script


Recommended Posts

Hi, this is in relation to my other post.

 

I note that when creating a script to draw lines and circles, my script starts off drawing the lines I then have a space and on a new line the circles are then drawn as per the following

 

line 0,0

2206,0

2206,152

0,152

0,0

0,20

2206,20

2206,132

0,132

 

circle 35,46 9

35,106 9

1073,120 9

1133,120 9

2168,58 9

2168,118 9

2118,58 9

2118,118 9

1938,118 9

 

The above script is absolutely fine, it draws a rectangle with circles inside.

 

Now when I expand the script to then start drawing another rectangle after the circles as in the following, the second rectangle never shows up

 

line 0,0

2206,0

2206,152

0,152

0,0

0,20

2206,20

2206,132

0,132

 

circle 35,46 9

35,106 9

1073,120 9

1133,120 9

2168,58 9

2168,118 9

2118,58 9

2118,118 9

1938,118 9

 

line 0,1000

2206,1000

2206,1152

0,1152

0,1000

0,1020

2206,1020

2206,1132

0,1132

 

Appreciate your advice on what I am doing wrong please?

 

Kind regards

 

Dave.

Link to comment
Share on other sites

Hi, thanks for your response.

 

I did not initially zoom extents as the second rectangle is only 1 metre above the first - I did subsequently zoom extents and it was nowhere to be seen.

 

I think what I am trying to understand is the syntax to end a command? I say this because using the script above, if I replace the circle part of the script with the second rectangle part then the script works as expected as in both rectangles are drawn.

 

If I remove the second rectangle part of the script it also works as expected, it draws both the first rectangle and circles.

 

Kind regards

 

Dave.

Link to comment
Share on other sites

Probably the same problem as your other post, the circle command finishes when you give the radius, so after the last circle is drawn there is no need for a blank line, this just causes the circle command to restart, and then you get an error because Autocad is expecting a coordinate and it gets the word "line".

Link to comment
Share on other sites

Just as a side issue you can do a script in 1 line also again watch for either a space or a blank line as a return, you need to look carefully at the example below there is a space on the end of the 1st "LIne" and 2 on the last "Line" but not on the Circle note though double space so circle command is repeated . Another trap is text depending on your style if you set a text height or not. Text pt abcde v's text pt abcde

 

line 0,0 2206,0 2206,152 0,152 0,0 0,20 2206,20 2206,132 0,132

circle 35,46 9 35,106 9 1073,120 9 1133,120 9 2168,58 9 2168,118 9 2118,58 9 2118,118 9 1938,118 9

line 0,1000 2206,1000 2206,1152 0,1152 0,1000 0,1020 2206,1020 2206,1132 0,1132

 

as above but with * as a space

line*0,0*2206,0*2206,152*0,152*0,0*0,20*2206,20*2206,132*0,132*

circle*35,46*9**35,106*9**1073,120*9**1133,120*9**2168,58*9**2168,118*9**2118,58*9**2118,118*9**1938,118*9

line*0,1000*2206,1000*2206,1152*0,1152*0,1000*0,1020*2206,1020*2206,1132*0,1132**

Link to comment
Share on other sites

Guys, many thanks for your replies, you have given me a better understanding of how to write my scripts from now on.

 

I will more than likely be back with questions on text, dimensions and linetypes, watch this space.....

Link to comment
Share on other sites

  • 2 weeks later...

Okay, back again.

 

The following are two screen shots of my dimension script and its output.

 

Screenshot 7a.jpg

 

You'll note at the left side there are two dimensions of 35 on the lower beam. The second higher dimension of 35 is meant to be a vertical dimension and is found in the script as

 

_dimlinear

35,106

0,152

@-50,152

 

Appreciate if you could advise me on what do I need to do to get this to be a vertical dimension? it should actually be 46.

Screenshot 7.jpg

Edited by ddoc
Link to comment
Share on other sites

I would stop and look seriously at 2 ways to do this type of item

1st use a dynamic block change a few dims and its redrawn. Yes you would need different styles.

2nd write it all in lisp, you only need to learn really one function the polar function (setq pt2 (polar pt1 angle distance)) (command "line" pt1 pt2 "")

 

You just need to keep track of your points you can reuse as the example the point varaibles so something like your beam may have pt1 pt2 pt3 pt4 and thats all the circles.

 

David Bethel posts amazing stuff done this way, just answer the questions.

 

This example is just the tip of the iceberg preset values pick std members and so on.

(setq pt1 (getpoint "\nPick lower left"))
(setq L (getdist "\nEnter distance"))
(setq H (getdist "\nEnter height"))
(setq pt2 (polar pt1 0.0 L))
(setq pt3 (polar pt2 (/ pi 2.0) H))
(setq pt4 (polar pt3 pi L))
(command "pline" pt1 pt2 pt3 pt4 "c")
(alert "wow a rectang")

; the circles
(setq offd (getdist "\nEnter circle offset"))
(setq pt3 (polar (polar pt1 0.0 offd) (/ pi 2.0) offd))) ; a double polar across and up
(setq rad "\nEnter circle radius")
(command "circle" pt3 rad) 

[/code]

Link to comment
Share on other sites

Watch the command line prompts, after entering the second extension line origin, autocad prompts you with a list of options - including either horizontal or vertical placement.

Link to comment
Share on other sites

BIGAL, many thanks for your suggestions, these have given me something to think about once I feel comfortable with scripting I should then have the time to start looking at Lisp, currently I have no experience with it and really need to remain within the confines of Excel to output scripts which, I might add is coming along nicely.

 

Steven, again, many thanks for your suggestion, in this instance it is the solution I was looking for - I noticed earlier today the very thing you suggest I then messed around placing the v in my script in various places until I got it to work.

 

I do really appreciate you guys taking the time to answer my questions.

 

Currently my script is drawing in model space so, at some point I will be looking for some advice on changing this to paper space - I have had a rough go at it, the result being that the beam opened in paper space once I had saved the template as a dwg however, the beam was drawn much larger than the paper so, I'm guessing I need to introduce a scale to the script and to also define some kind of new origin to place the geometry at as I note it came into paper space at the low left corner of the margin but, this problem is for another time or at least not until I have completed the model space script.

Edited by ddoc
Future Problems!
Link to comment
Share on other sites

Stay drawing in model space and use layouts for the scaling thats what they were designed for. Back to a lisp and dim using the beam draw using pt1 pt2 pt3 pt4 to make rectang, then DIM hor pt3 pt4 then a pt5 which is dummy dim point above rectang, dim ver pt1 centre circle then dummy pt to left and so on. I draw on paper as I write code the pt numbers so I dont lose track, for your beam never redo pt1-pt4 just add new ones as everthing is offset from a corner. You can break the beam creation into multi lisps, draw shape, 1 or 2 bolts on end, bolt in middle, this way you do not have to recode for every beam type.

Link to comment
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
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...