Lisp Inserting a block to match UCS

Lisp Inserting a block to match UCS

mdhutchinson
Advisor Advisor
877 Views
3 Replies
Message 1 of 4

Lisp Inserting a block to match UCS

mdhutchinson
Advisor
Advisor

I have some code that inserts a 3d block via the command function. The 3d blocks in this app are intended to come in rotated to align with the World coordinate system... how might I change the command call to cause it to align with the World coordinate system even if the user has a UCS set up that does not align with the WCS? 

 

Optionally, I could temporarily save the UCS, set the WCS current then return the user to UCS after the block insertion... but this sounds a bit of an overkill.

 

Thoughts?

0 Likes
878 Views
3 Replies
Replies (3)
Message 2 of 4

stevor
Collaborator
Collaborator
Post your .LSP code, of course.
S
0 Likes
Message 3 of 4

Kent1Cooper
Consultant
Consultant

You should be able to do that without messing with the Coordinate System, by using (entmake) instead of an Insert command.  You would need to get the insertion point from the User first, presumably with (getpoint), and apply (trans) to that to get its WCS coordinates for the insertion point you put into the entity data list in (entmake).  You would include the WCS's extrusion direction (210 0.0 0.0 1.0).  It sounds like you would include 0 rotation; if non-default scale factors may be needed but not standardized [e.g. not based on a calculation from other input, or some System Variable such as DIMSCALE], you would also need to ask the User for those beforehand.  You could also control other things, such as have them always on a standard Layer without needing to set that Layer current.

Kent Cooper, AIA
0 Likes
Message 4 of 4

hmsilva
Mentor
Mentor

@mdhutchinson wrote:

I have some code that inserts a 3d block via the command function. The 3d blocks in this app are intended to come in rotated to align with the World coordinate system... how might I change the command call to cause it to align with the World coordinate system even if the user has a UCS set up that does not align with the WCS? 


Two ways:

 

the simplest method

(command "_insert" "YourBlockName" ... )
(setq blk (entget (entlast)))
(entmod (subst (cons 50 0.0) (assoc 50 blk) (setq blk (entget (entlast)))))

 

or the hardest method,

get the angle type (to convert the angle), in my case is Decimal Degrees,
get the direction ( to add or subtract from 0.0 angle), in my case is counterclockwise,

(command "_insert" "YourBlockName" "_S" 1 "_R" (* 180.0 (/ (- 0.0 (angle '(0 0 0) (getvar 'UCSXDIR))) pi)) pt)

 


Henrique

EESignature

0 Likes