- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi guys,
I want to mention upfront that I am a newbie to AutoCAD and AutoLISP. I am trying to help a colleague to automate certain processes. I am using AUtoCAD in German so the commands are in German but I added a translation comment for each command type.
In the code snippet, we need to select a poly line. Then I need to create rectangle orthogonal to the poly line to use it for a sweep command later on (not in the snippet). To get the orthogonal rectangle, I create a new User Coordinate System (UCS) with the XY plane orthogonal to the poly line. Then create the rectangle on the XY plane and switch back to the original UCS.
Unfortunately, the code is not working. In detail, the command where I create my new UCS and switch back to the old one, as well as when creating the rectangle. I debugged my code and when I apply
(defun C:POLY_TEST (/)
(setq poly (car (entsel "\nSelect Polyline: ")))
(setq lst (3d-coord->pt-lst (vlax-get (vlax-ename->vla-object poly) 'Coordinates)))
(setq
firstPoint (nth 0 lst);First Point of Poly line
x (nth 0 firstPoint)
y (nth 1 firstPoint)
z (nth 2 firstPoint)
secondPoint (nth 1 lst);Second point of poly line
x2 (nth 0 secondPoint)
y2 (nth 1 secondPoint)
z2 (nth 2 secondPoint)
lastPoint (nth (- (length lst) 1) lst)
xEnd (nth 0 lastPoint)
yEnd (nth 1 lastPoint)
zEnd (nth 2 lastPoint)
vXYx (- x2 x); direction vector between first and second point of poly line
vXYy (- y2 y)
vXYz (- z2 z)
uXYx 0;direction vector pointing in negative z
uXYy 0
uXYz -1
rXYx (- (* vXYy uXYz) (* vXYz uXYy)); cross product to get orthogonal vector between two previous vectors
rXYy (- (* vXYz uXYx) (* vXYx uXYz))
rXYz (- (* vXYx uXYy) (* vXYy uXYx))
rLen (sqrt (+ (* rXYx rXYx) (* rXYy rXYy) (* rXYz rXYz))); vector length
rXYx (/ rXYx rLen); normalizing vector
rXYy (/ rXYy rLen)
rXYz (/ rXYz rLen)
pXYx (+ x uXYx rXYx);calculate point on plane orthogonal to vector between first and second point of poly line
pXYy (+ y uXYy rXYy)
pXYz (+ z uXYz rXYz)
)
(command "PUNKT" (strcat (rtos x 2 11) "," (rtos y 2 11) "," (rtos z 2 11)) ""); PUNKT = POINT
(setq origin (entget (entlast)))
(command "PUNKT" (strcat (rtos x 2 11) "," (rtos y 2 11) "," (rtos (- z 1) 2 11)) "")
(setq negX (entget (entlast)))
(command "PUNKT" (strcat (rtos pXYx 2 11) "," (rtos pXYy 2 11) "," (rtos pXYz 2 11)) "")
(setq pXY (entget (entlast)))
(command "BKS" origin negX pXY ); BKS = UCS - NOT WORKING!! -> generate new User coordinate system with origin at first point of poly line which XY plane is orthogonal to poly line
(setq bksNew (entget (entlast)))
(setq diameter 10.0)
(command "PUNKT" (strcat (rtos (/ (+ diameter 2) -2) 2 11) "," (rtos (/ (+ diameter 2) -2) 2 11) "," (rtos 0 2 11)) "")
(setq bottomLeft (entget (entlast))); bottom left point of rectangle
(command "PUNKT" (strcat (rtos (/ (+ diameter 2) 2) 2 11) "," (rtos (/ (+ diameter 2) 2) 2 11) "," (rtos 0 2 11)) "")
(setq topRight (entget (entlast))); top right point of rectangle
(command "RECHTECK" bottomLeft topRight); RECHTECK = RECTANGLE - NOT WORKING!! -> create rectangle orthogonal to poly line
(setq rect (entget (entlast)))
(command "BKS" "VO");BKS = UCS; VO = Vorher (Before/Previous) - NOT WORKING!! -> moving back to original UCS
(setq bksOld (entget (entlast)))
(command "LÖSCHEN" origin negX pXY bottomLeft topRight ""); LÖSCHEN = DELETE / REMOVE -> Deleting support points for UCS and rectangle
(princ)
)
Solved! Go to Solution.