Macro draw line parallel to two points with 3 segments

Macro draw line parallel to two points with 3 segments

Anonymous
Not applicable
3,007 Views
34 Replies
Message 1 of 35

Macro draw line parallel to two points with 3 segments

Anonymous
Not applicable
Hi All

I am trying to use the below macro to draw a line with 3 segments that connects two points, the middle segment runs parrallel and offset to the points and the first and third segments join to each point at either end . The points are of a variable distance. My idea is redefine the ucs along the vector of the points and then select the second point(block) to define LASTPOINT then use the userr1-5 variables to draw the desired polyline but its not quiet working out.

^C^CUCS;\\;SELECT;SI;\setvar;USERR1;$M=$(index,0,$(GETVAR,LASTPOINT));setvar;USERR4;1.156;setvar;USERR3;$(-,$(getvar,USERR2)(,$(getvar,USERR4));PLINE;0,0;@0,1.156;@0,$(GETENV,USERR3);@0,-1.156;


Hopefully someone can advise as to my mistakes and help me learn a bit more.


Regards

0 Likes
Accepted solutions (1)
3,008 Views
34 Replies
Replies (34)
Message 21 of 35

Kent1Cooper
Consultant
Consultant

Do you have any running Object Snap mode(s) on?

Kent Cooper, AIA
0 Likes
Message 22 of 35

Anonymous
Not applicable
No its when i draw from right to left (backwards) the line is invereted
0 Likes
Message 23 of 35

Kent1Cooper
Consultant
Consultant

That's because setting the UCS to match a Polyline is affected by the direction in which the Polyline was drawn.  If you are using a macro because you have Acad LT, I don't know whether you can do anything about that [other than be conscious of it and always work in the more left-to-right/down-to-up direction]; if you have full AutoCAD, an AutoLisp routine could easily account for that, and turn it in the more upright direction.

Kent Cooper, AIA
0 Likes
Message 24 of 35

Anonymous
Not applicable

^C^Csetenv;V1;$M=$(Substr,$(getvar,ucsxdir),1,1);setenv;V2;-;_setvar;ucsaxisang;$(if,$(eq, $(getenv,V1),$(getenv,V2)),180,5));ucs;x;;;

 

 

What if i entered something like the above into he code to recognize if the x axis direction is negative and flip it back to a positive value, its just a theory but i can t make it work. perhaps it cant be done ?

0 Likes
Message 25 of 35

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

^C^Csetenv;V1;$M=$(Substr,$(getvar,ucsxdir),1,1);setenv;V2;-;_setvar;ucsaxisang;$(if,$(eq, $(getenv,V1),$(getenv,V2)),180,5));ucs;x;;;

....


I find that while setVAR can be used as a command name, setENV cannot [in Acad2016 that I have here], so I assume it should go into $(setenv.... expressions the way GETenv is being used.

 

UCSXDIR as reported by $(getvar... is not like what you get when you type UCSXDIR at the command line.  It's a list of 3 numbers, not a text string.  So V2 and the resulting comparison would have to be done in a different way.

 

I don't see what the 5 is for near the end -- is it supposed to rotate the UCS 5 degrees around the X axis if it's already aimed the "right" way?

Kent Cooper, AIA
0 Likes
Message 26 of 35

steven-g
Mentor
Mentor

This is getting complicated now, there has to be a way just to draw the 3 segment line simply from 2 clicks, I'm still trying things here as well.

 

As a note setenv is actually a working command in LT one of LT's few advantages over full Autocad which can only use it from within Lisp

Message 27 of 35

Anonymous
Not applicable
The UCSXDIR returns the vector of x when x is in its normal state it is 1,0,0 , when it moves into a negative plane(which is my issue) it becomes prefixed with a negative. I was trying to use substring to extract this "-" symbol and prepare an if statement to set the ucsaxisang to 180 if it is present and flip the x ucs.

5 is the minimum value ucsaxisang accepts. Another value might be more suitable.
0 Likes
Message 28 of 35

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:
The UCSXDIR returns the vector of x when x is in its normal state it is 1,0,0 , when it moves into a negative plane(which is my issue) it becomes prefixed with a negative. I was trying to use substring to extract this "-" symbol and prepare an if statement to set the ucsaxisang to 180 if it is present and flip the x ucs.

5 is the minimum value ucsaxisang accepts. Another value might be more suitable.

But the value of UCSXDIR is not  a string, so you can't extract the "-" from the beginning of it that way.  I don't know how many of these options are available in Diesel functions [I have barely ever used it], but in AutoLisp you could use

 

(minusp (car (getvar 'ucsxdir)))

 

which would return T in your negative-plane situation or nil otherwise.  Or you could convert the first number in the value to a string, and then extract its first character:

 

(substr (rtos (car (getvar 'ucsxdir)) 2 3) 1 1)

 

[or about any non-zero precision value you like in place of the 3], in which case you would have either "-" or some digit to compare to.

 

In any case, do you need the V2 thing saved as an environment variable?  Can't you just check whether that first character is "-" directly?

 

Rather than set a value into UCSAXISANG and then call up a UCS command and rotate about the X axis by the default value, can you just put the (if) part in a different place?  Forget about UCSAXISANG.  Call up UCS and the X option, and then put in the (if) test, with the answer to the rotation being 180 if you're in negative-plane territory, or 0 if you're not.

Kent Cooper, AIA
Message 29 of 35

steven-g
Mentor
Mentor
Accepted solution

I think this works, what suprised me is setting the ucs to last drawn object doesn't take into consideration the direction it was drawn it just goes to the nearest point and aligns with the object. So forcing the ucs to go to the last end drawn will make the ucs reverse direction and make the coordinates work as expected. So try this version.

^C^Cortho;off;pline;\\;UCS;ob;$M=$(getvar,lastpoint);ortho;on;pe;l;e;i;@-1,1;x;r;e;i;@1,1;x;;ucs;w
0 Likes
Message 30 of 35

Kent1Cooper
Consultant
Consultant

@steven-g wrote:

... setting the ucs to last drawn object doesn't take into consideration the direction it was drawn it just goes to the nearest point and aligns with the object. So forcing the ucs to go to the last end drawn will make the ucs reverse direction and make the coordinates work as expected. ....


... but then it's upside-down when you draw from left to right....

Kent Cooper, AIA
Message 31 of 35

steven-g
Mentor
Mentor

@Kent1Cooper wrote:

... but then it's upside-down when you draw from left to right....


That's the idea, when you draw left to right the pline is offset down, and when you draw right to left the pline is offset up (Smiley Very Happy or the other way round) but the pick order determines the direction of the bump)

0 Likes
Message 32 of 35

Kent1Cooper
Consultant
Consultant

@steven-g wrote:

@Kent1Cooper wrote:

... but then it's upside-down when you draw from left to right....


That's the idea, when you draw left to right the pline is offset down, and when you draw right to left the pline is offset up (Smiley Very Happy or the other way round) but the pick order determines the direction of the bump)


I had the impression they wanted it offset in the upward-leftward direction, no matter which way you picked the points, but a clarification from the OP would be in order.  I think that was the whole reason for wanting to turn the UCS around if the direction between points was more leftward than rightward.

Kent Cooper, AIA
0 Likes
Message 33 of 35

steven-g
Mentor
Mentor

Hmmm, I didn't read it that way but you could be right?

0 Likes
Message 34 of 35

Anonymous
Not applicable
The line is not always required to be offset in the upward-leftward direction, in fact it will alternate so this might be a useful trait, i just need to get used to using it. Thanks for all your help guys i will add some layer settings and reset the ortho when done. But i think we have a solution. Would including snaps for center points when drawing the intial pline work?
Message 35 of 35

steven-g
Mentor
Mentor

When ever an input is required you can use the first 3 letters of an osnap to overide or force any single osnap point so it would look like

pline;cen;\

or in some cases "non" can be useful to ignore all osnaps. You have to do this for each input, it is a one time only event, not once in the macro but for every point in the macro.

 

 

This has been an interesting post, I learnt a lot from it Thanks

0 Likes