I'm looking to translate some block line endpoints selected with 'nentsel' +
'entget' from OBS (Object Co-ordinate System) to WCS (World Co-ordinate
System).
I've experimented with 'trans' and got it to work OK using co-ordinate codes
such as:
(trans point 1 0 0) or (trans point 2 0 0)
However, I couldn't get it to work using the entity name returned by
'nentsel' and there doesn't seem to be a co-ordinate system code for OCS.
Can you mix entity names (ename) and codes within 'trans', such as:
(trans point ename code [disp])?
The manual suggests that you can, but for me it just returns nil.
If I understand the procedure correctly, I select a line entity using
'nentsel', then check to see if the line is embedded within a complex entity
(block). If it is, I apply 'trans' to convert the line endpoints from OCS to
WCS.
What is the best way to check for a complex entity from the list returned by
'nentsel'? Look for <Entity name: **********> using 'last'?
What syntax should I use with 'trans' to convert my line endpoints from OCS
to WCS? Entity names or co-ordinate codes?
I got the impression that if I could get 'trans' working using the entity
name for OCS and the code 1 for WCS, then I could apply 'trans' regardless
of whether the selected line was in a block or not. If it wasn't, then OCS
would be equivalent to WCS and 'trans' would return null.
Any help appreciated.
TIA
--
Mike
Please remove 'SAFETYCATCH' from E-mail address before firing off your reply
--
"mlv" <mike.v...@jetSAFETYCATCH.uk> wrote in message news:8t8no2$1ch$1...@soap.pipex.net...
Hi Pi!
Well, if there wasn't a typo in my posting, you would have known the answer!
OCS = Object Co-ordinate System (such as blocks use when returning endpoints
of lines, for example).
Unfortunately, I typed 'OBS' by mistake.
I'm sure that's not the reason I haven't received any replies to my
question. I wonder what is!
Best regards
P.C.
mlv skrev i meddelelsen <8t9jar$hn3$1...@soap.pipex.net>...
In a "world" described by standard x y z vectors, you can "move" a point
with standart matrix manipulations like the poverfull mapcar and apply. But
with Trans you first you need to tell the "plane" from which the point are
described and onto which it is "moved" ; The "from / to" .
Now I rather use matrixes, as the "disp" are much easyer understood from
tradisional equalations , -------- also I think you shuld not use "trans"
before you know exactly how things like distances , vectors and projections
work, at that point you proberly chose other way's to "transform" a point
from one plane to another plane described in "World" coordinates.
You can use a 2D entity to set a "new" coordinate system, but this will just
be a system described from the x and y values ; the new cooerdinate system
will have the same Z vector. Anyway when you do solids , you often are
restricted by object cooerdinate systems, then you se, that "real" 3D
objects will not return a "object cooerdinate system" when you need to
change UCS, to be able to edit for instance a 3Dpoly, that's becaurse the
3Dpoly are described in world cooerdinates and a polyline is a 2D object
described in terms of eiter a w or a user cooerdinate system.
Anyway I have to tell, that it's been years since I used Trans, and decided
not to, ----- but I think what you shuld look for, are the "210" value codes
in the sublist returned by "entget", they are the ones who tell the
direction vector that describe the entity cooerdinate system, did you try to
"Subst" the (cdr(assoc 210(entget(car(entsel)))))
codes with what you calculated with "trans", that's a way to learn to use
trans.
If not, try making two polylines ; one in "world" and one on a UCS of your
choice, and then check the "210" values with
(cdr(assoc 210(entget(car(entsel)))))
Nice though that a side effect are that you can extract the paperspace
scale, is _that_ what you need ?
Best regards
P.C.
mlv skrev i meddelelsen <8t8no2$1ch$1...@soap.pipex.net>...
Thanks for the information - I'll go and experiment some more.
To explain further, the problem I have is that when I use 'nentsel' to
select an entity, sometimes the selected entity is within a complex entity
(block) and sometimes it isn't. When the entity is within a block, the point
co-ordinates returned by 'assoc' are given in the block's OCS. For my
application, first I need to identify that the selected entity is within a
block, and, if it is, I then need to translate the point co-ordinates from
OCS into WCS.
For example, I have a lisp routine that (amongst other things) has to return
the centre point of a selected circle. The circle may or may not be part of
a complex entity (block).
I use the autolisp function 'nentsel' so that I can check that the selected
entity definitely is a circle, regardless of whether it is embedded within a
block or not. If the entity is a circle embedded within a block, then I
need to translate the circle centre point (assoc 10) from the OCS (Object
Co-ordinate System) to the WCS (World Co-ordinate System).
I've spent hours trying to persuade the autolisp 'trans' function to work
with absolutely no success whatsoever.
Maybe someone can show me where I'm going wrong. The following lisp extracts
select a circle and find its centre.
EXAMPLE:
Pick a circle that is within a block called 'test_block' using:
(setq ent (nentsel))
The variable 'ent' is set to:
(<Entity name: 5fc0858> (54.6191 240.593 0.0) ((1.0 0.0 0.0) (0.0 1.0 0.0)
(0.0
0.0 1.0) (0.0 200.0 0.0)) (<Entity name: 5fc0890>))
Obtain the entity codes with:
(setq entcds (entget ent))
The variable 'entcds' is set to:
((-1 . <Entity name: 5fc0858>) (0 . "CIRCLE") (5 . "193") (100 .
"AcDbEntity")
(67 . 0) (8 . "0") (100 . "AcDbCircle") (10 50.0 50.0 0.0) (40 . 10.0) (210
0.0
0.0 1.0))
Obtain the entity name of the circle with:
(setq circ (car ent))
The variable 'circ' is set to:
<Entity name: 5fc0858>
Obtain the entity name of the parent block with:
(setq blk (car (last ent)))
The variable 'blk' is set to:
<Entity name: 5fc0890>
Obtain the centre of the circle picked with 'nentsel' with:
(setq ctr (cdr (assoc 10 entcds)))
The variable 'ctr' is set to:
(50.0 50.0 0.0)
Because the selected circle is within a block, the centre point (ctr) is
relative to the insertion point of that block and is given in the OCS. I
need to translate the point 'ctr' from the OCS to the WCS using the autolisp
'trans' function.
If necessary, I can obtain the entity codes of the parent block with:
(setq blkcds (entget blk))
The variable 'blkcds' is then set to:
((-1 . <Entity name: 5fc0890>) (0 . "INSERT") (5 . "19A") (100 .
"AcDbEntity")
(67 . 0) (8 . "0") (100 . "AcDbBlockReference") (2 . "TEST_BLOCK") (10 0.0
200.0 0.0) (41 . 1.0) (42 . 1.0) (43 . 1.0) (50 . 0.0) (70 . 0) (71 . 0) (44
.
0.0) (45 . 0.0) (210 0.0 0.0 1.0))
I can also obtain the insert point of the parent block with:
(setq ip (cdr (assoc 10 blkcds)))
The variable 'ip' is set to:
(0.0 200.0 0.0)
The true (WCS) centre of the selected circle is:
X = 50.00 Y = 250.00 Z = 0.00
so I'm looking for 'trans' to return:
(50.00 250.00 0.00)
but it doesn't, no matter what information I give it.
I would have expected something like:
(trans ctr circ blk 0) or
(trans ctr circ 0 0)
to work, but they don't. They both return nil.
Entering (trans ctr blk 0 0) returns:
(50.0 50.0 0.0)
I get the impression that 'trans' doesn't like the circle entity name set in
the variable 'circ', but I can't think why. Maybe 'trans' doesn't work on
sub-entities.
I've tried everything I can think of, including hitting the keyboard with a
very large hammer. None of it works :-(
Can anyone point me in the right direction, please?
Thanks
Try this :
First extract a direction vector for a circle you put in on a UCS of your
choice. ------ be sure you are on a UCS other than world, to add the "210"
codes to the assoc lists
(setq a(assoc 210(entget(car(entsel)))))
Guess that work, that will pass the direction vector , or rather a point.
To make it into a vector xyz values are simply added xx yy zz with mapcar
'+.
Then draw a 3dpoly from (cdr a) to (mapcar '+ (setq b(cdr a)) b)
Guess I shuld rather write;
(setq a(assoc 210(entget(car(entsel))))) ; standard procedure
(setq b(cdr a)) ; you
remove 210
(setq c(mapcar '+ b b)) ; other point of
vector
Then ofcaurse ; 3dpoly from !b to !c
Now if you done the direction vector on same UCS as the circle, you need to
vpoint to be able to se other than a "point" :))
Il'l check what you wrote, ---- but try this first , your "mistake" could be
this.
Best regards
P.C.
mlv skrev i meddelelsen <8tjl4k$n6s$1...@soap.pipex.net>...
> Thanks for the information - I'll go and experiment some more.
>
> To explain further, the problem I have is that when I use 'nentsel' to
> select an entity, sometimes the selected entity is within a complex entity
> (block) and sometimes it isn't. When the entity is within a block, the point
> co-ordinates returned by 'assoc' are given in the block's OCS. For my
> application, first I need to identify that the selected entity is within a
> block, and, if it is, I then need to translate the point co-ordinates from
> OCS into WCS.
Maybe as a workaround you could try to set the UCS to the OCS of your
"insert" (command "_UCS" "_OBJECT" blk) then call (trans point 1 0) and
then set the UCS to "previous".
I could not get it to work with "ename" either.
Matthias
AFAIK, (trans) can't cope with the translations, rotations and scaling of a
block. You *have* to use the transformation matrix given to you by (nentsel)
to compute the coordinates.
I found a nice little program by Tony Tanzillo (homepage at
http://ourworld.compuserve.com/homepages/tonyt/ ) exactly for this purpose,
but I think it's under copyright, so I don't post it here according to
Tanzillo's remark concerning the distribution of his programs. The program
is not on the web, I only found it on page 285 in the book (sorry, it's in
german)
Die AutoCAD Programmierung
Dietmar Rudolph
Edition Autodesk
Rossipaul Verlag, München
ISBN 3-87686-245-0
You should mail Tanzillo, the program is called MKStrans
Jo Weber
That is probably what's killing (trans). As a UCS to my knowledge can't
be scaled (it can be rotated and translated of course) this is probably
the cause for (trans) refusing to work with "insert"-<enames>. My
workaround mentioned earlier will then of course also work only if the
block is scaled to (1,1,1) if at all.
Matthias
The problem is that the block's OCS (as given by group code 210) is the CS
which was active at the time of definition and has nothing to do with
translations, rotations and scaling of the block. So trans works fine with
entity names - yes, it really does, even with blocks - but in best case you
get the same point back, if OCS and current CS are the same. If not, you
find yourself somewhere offplace without any real control of the
translations and so on ...
There is no way to bypass the matrix manipulations by means of the list
given back by nentsel.
I don't know why you get 'nil' when using trans with element names. I can
reproduce this effect when assigning a variable to an object, erasing it and
then calling trans using the previously defined variable now pointing to the
big trash heap ...
Delete -nospam to get my valid e-mail adress