TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Woabow on January 31, 2013, 10:02:33 AM
-
After spending some time to solve it myself I'm feeling close, but I see a lot of matrix calculations which I do not understand completely.
My problem: I just want to create a named UCS with Visual lisp code like this, where the UCS follows the OCS of a selected block
(while (not (and
(setq nsel (entsel "\nSelect Block: "))
(= (cdr (assoc 0 (entget (setq ent (car nsel))))) "INSERT")
))
)
(setq vlobj (vlax-ename->vla-object ent))
(setq insertion (vlax-get vlobj 'InsertionPoint))
(setq no (vlax-get vlobj 'Normal))
(setq rotation (vlax-get vlobj 'Rotation))
(setq ocs (vla-add (vla-get-UserCoordinateSystems (vla-get-activedocument (vlax-get-acad-object))
(vlax-3d-Point '(insertion?))
(vlax-3d-Point '(? ? ?))
(vlax-3d-Point '(? ? ?))
"SCOCS"
)
)
-
Maybe:
(defun c:bucs ( / e i n o z )
(if (setq e (ssget "_+.:E:S" '((0 . "INSERT"))))
(progn
(setq e (entget (ssname e 0))
z (cdr (assoc 210 e))
o (cdr (assoc 010 e))
i 0
)
(while (tblsearch "UCS" (setq n (strcat "BUCS" (itoa (setq i (1+ i)))))))
(vlax-invoke
(vla-get-usercoordinatesystems (vla-get-activedocument (vlax-get-acad-object)))
'add
(trans o z 0)
(trans (mapcar '+ o '(1.0 0.0 0.0)) z 0)
(trans (mapcar '+ o '(0.0 1.0 0.0)) z 0)
n
)
)
)
(princ)
)
-
Thanks Lee, I was about the same point as you, with less nice code, that is...
But the UCS does not follow the rotation of the block, see attached DWG
If I do the "UCS" command with "Object" option it does follow the rotation like I would like it to do.
-
Perhaps:
(defun c:bucs ( / e i n o r z )
(if (setq e (ssget "_+.:E:S" '((0 . "INSERT"))))
(progn
(setq e (entget (ssname e 0))
z (cdr (assoc 210 e))
o (cdr (assoc 010 e))
r (cdr (assoc 050 e))
i 0
)
(while (tblsearch "UCS" (setq n (strcat "BUCS" (itoa (setq i (1+ i)))))))
(vlax-invoke
(vla-get-usercoordinatesystems (vla-get-activedocument (vlax-get-acad-object)))
'add
(trans o z 0)
(trans (polar o r 1.0) z 0)
(trans (polar o (+ r (/ pi 2.0)) 1.0) z 0)
n
)
)
)
(princ)
)
-
This does the trick, many thanks (again :-)).
-
This does the trick, many thanks (again :-)).
You're welcome Woabow :-)
-
Hi Lee Mac
Do you have an idea how to set UCS
on face of 3d solid like box?
(then the Z axis will be perpendicularly to it)?
Kind regards,
Oleg
-
Hi Lee Mac
Do you have an idea how to set UCS
on face of 3d solid like box?
(then the Z axis will be perpendicularly to it)?
Kind regards,
Oleg
Hi Fixo,
Unfortunately, I don't know how to determine the normal vector of a selected face, or even how to determine the selected face of a 3D Solid since it seems that solids are not entirely exposed to AutoLISP / Visual LISP. :|
-
Hi oleg,
You can look at the Autodesk.AutoCAD.BoundaryRepresentation.Brep .NET class to access to 3d solid datas.
I tried something with a.NET defined LISP function here:
http://www.theswamp.org/index.php?topic=39278.msg445148#msg445148
-
Thanks Gilles, I know this way but I need to do it using lisp
Kind regards,
Oltg