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

Problem with TRANS function

8 REPLIES 8
Reply
Message 1 of 9
coralie.jacobi
553 Views, 8 Replies

Problem with TRANS function

Hi, I'm trying to adjust a point using a base point and xscale and yscale factors. It works great in WCS, but now I need to getit to work when there is a UCS. Here is my code;

 

(defun textmod (itm / entxy oldx oldy newx newy newxyWCS)
 (setq entxy (trans itm 0 1)) ; change to UCS
 (setq oldx (car entxy))
 (setq oldy (cadr entxy))
 (setq newx (+ xbase (* xscale (- oldx xbase))))
 (setq newy (+ ybase (* yscale (- oldy ybase))))
        (setq newxy (list newx newy 0.0))
        (setq newxyWCS (trans newxy 1 0)) ; change back to WCS
 (setq newitm (list (car newxyWCS)(cadr newxyWCS) 0.0))
        (setq itm (list newx newy 0.0))
)

 

In the following example I use an Xscale = 1 and a Yscale = 2. The x-coordinate doesn't change after the calculation, but when I use trans to put it back to WCS it doesn't put it back to the same as where it started.

Can anybody tell me what I'm doing wrong. or how to correct it?

 

ITM = (118.914 60.5789 0.0)
ENTXY = (34.0484 16.99 0.0)
NEWXY = (34.0484 20.5601 0.0)
NEWITM = (116.503 63.2127 0.0)

 

thanks

cj

 

8 REPLIES 8
Message 2 of 9

I don't see anything setting values into xbase, xscale, ybase or yscale.  Are they coming from outside this part, in some larger routine?

Kent Cooper, AIA
Message 3 of 9

Yes Kent, they are getting set outside the function in the routine. I am trying to adjust some older code, and once I get the trans sorted out, then I will fix it to pass those variables as well.

Message 4 of 9

If xbase and ybase are coordinates of a reference location, you may also need to (trans) that into the current UCS before you use those values in calculations with other numbers that are in UCS terms.

Kent Cooper, AIA
Message 5 of 9

Ok, I can see that, but why doesn't the x-coordinate translate back to the same value as it started out as in ITM. The x-coordinate is the same in ENTXY and NEWXY which it should because I had a Xscale of 1. But the TRANS command doens't put it back to the same x-coordinate in WCS as it started! That's what I don't understand. The x-coordinate of ITM and NEWITM should be the same, and they are not.

 

cj

Message 6 of 9


@cjacobi wrote:

.... The x-coordinate is the same in ENTXY and NEWXY which it should because I had a Xscale of 1. But the TRANS command doens't put it back to the same x-coordinate in WCS as it started! That's what I don't understand. The x-coordinate of ITM and NEWITM should be the same, and they are not.

....


That's because you've changed the location in the Y direction in the UCS, which I assume, in your trial situation, must not be parallel to the Y direction in the WCS, so moving it also affects the X location in the WCS.

 

For a visualizable scenario with round numbers, consider the WCS location 1,1,0.  If you are in a UCS whose origin is still at WCS 0,0,0 but that is rotated 90 degree counterclockwise, so that X is up and Y is to the left, that location will (trans) into UCS coordinates 1,-1,0.  Now determine a new location that has the same UCS X coordinate but has the UCS Y coordinate changed, let's say move it up 1 in the UCS, to 1,0,0.  That's WCS location 0,1,0, which of course has a different WCS X coordinate than the original 1,1,0 location.

 

If the UCS just has a different origin, but has its XY axes parallel to those of the WCS, this wouldn't happen.  Given the same WCS 1,1,0 location, if you're in a UCS that's parallel but with its origin at 1,1,0, that location is UCS 0,0,0.  If you add to the Y coordinate and make it UCS 0,1,0, that will (trans) back to WCS 1,2,0, which does keep the original X coordinate.

 

EDIT:  And "parallel" means only that -- they can even aim in opposite directions.  With a UCS whose origin is at WCS 0,0,0 but that is rotated 180 degrees, WCS 1,1,0 is UCS -1,-1,0.  Raising the UCS Y coordinate by 1 again gives UCS -1,0,0, which is WCS 1,0,0, again retaining the original X value.

Kent Cooper, AIA
Message 7 of 9

Well that made my head hurt reading that BUT I get it. THANKS! Smiley Very Happy

 

Now I just have to figure out why my code doesn't work the way I want it to. I have added transposing the base point to UCS before I do the recalc on the point. But something is still wrong. All I'm trying to do is move text or a block using it's insertion point.

 

thanks again for your explanation. It does make much more sence to me now.

 

cj

Message 8 of 9


@cjacobi wrote:

Well that made my head hurt ... 

.... All I'm trying to do is move text or a block using it's insertion point.

....


Yeah, I considered trying to draw something to help illustrate it, but hoped the round-numbers comparison would be clear enough.

 

Can you post an image or a drawing showing a before condition, the basis for the movement direction and distance, and the after condition you're looking for?

Kent Cooper, AIA
Message 9 of 9

Here you go.....it's basicall a basic cross-section and if we need to change the exageration that is what this routine is to do. The first pic is the base section. Polylines, text, and blocks. the second is after I run the command in WCS. Works great. The third is with a UCS. The linework adjusts properly, but the text and blocks do not.

 

cj

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

Post to forums  

Autodesk Design & Make Report

”Boost