Code Red > AutoLISP (Vanilla / Visual)

UCS effect on lsp's

(1/4) > >>

PHX cadie:
Not sure if I should even ask this, not having an understanding of any of the languages, lsp or any.
Currently during mostly Mech stuff we have 3 lsp routines that are very handy, endpipe, (that yin-yang thing), cuttube (the figure 8 symbol) and centerline. All these routines work if the UCS is to the world, but coming from a Civil firm I don't do everything to the world UCS.

Is there a fix to get lsp's to function with a user (?) UCS

dan19936:
A quick answer is that when in lisp, mixing point selection via (command "autocadcommand" ...) which uses local user UCS coordinates and entget which uses world WCS coordinates will get you in trouble. Use the trans function to convert between WCS & UCS. For example:


;;; quick COPY text or insert from insertion point
(defun-q c:CS1  ( / ss1 e1 ins1)
  (BCV-ERROR-INIT (list (list "cmdecho" 0 "osnapcoord" 0 "osmode" (getvar "osmode")) T))
  (SETV "osmode" 1088)   ;turn on insertion snap for text pick
  (if (and (setq ss1 (ssget "+.:S:E:L" '((0 . "INSERT,*TEXT"))))   ;select one insert on unlocked layer
           (setq e1  (ssname ss1 0))            ;get entity name
           (setq ins1 (trans (cdr (assoc 10 (entget e1))) 0 1))      ;get insertion point
      ) ;and
    (progn
      (command "copy" "si" e1 ins1)
      (RSETV "osmode") ;reset to normal snaps for final pick
      (BCV_CMDACTIVE nil)
    ) ;progn
  ) ;if
  (BCV-ERROR-RESTORE)
)


the trans function converts the entget point from WCS 0 to UCS 1

Dan

sinc:

--- Quote from: PHX cadie on October 11, 2006, 07:43:08 PM ---All these routines work if the UCS is to the world, but coming from a Civil firm I don't do everything to the world UCS.

--- End quote ---

Yowsa!  If you don't use the world UCS, you get incorrect bearings.  I take it you do nothing with bearings?

I work in a Civil firm, and we basically use nothing BUT the world UCS...


--- Quote ---Is there a fix to get lsp's to function with a user (?) UCS

--- End quote ---

You should be able to get any Lisp to function any way you want it to, it's just a matter of making the right adjustments to the code...

PHX cadie:
Sinc:
 Lets say on the overall site plan a Bldg has a slight rotation, compared to North to the top of the sheet. On the Bldg plan I'd use WCSROT to get the walls square with that sheet and UCS, n, ob to do a section or elevation.  If I do a bearing/dist or ID its on the WCS.
Hope I didn't scare ya

Dan:
 Sorry I forgot to mention. I tried the 05 tutorials for lisp and had to start the 2nd chapter resorting to the backup examples because my work from the first chapter failed  :oops:  :-D
It may take awhile but I need to study on your response.

Thanks for all the replies!
I'll be back!

I'm not the sharpest knife in the kitchen, but I'm not the dullest either

gile:
Hi,


--- Quote ---(setq ins1 (trans (cdr (assoc 10 (entget e1))) 0 1))      ;get insertion point
--- End quote ---

This will work only if UCS XY plane is parallel to WCS XY plane.
Insertion point coordinates of a block or text are defined in OCS (Object Coordinates System).

The following codes will work whatever the current UCS and the entity OCS :


--- Code: ---(setq ins1 (trans (cdr (assoc 10 (entget e1))) e1 1))
--- End code ---
or

--- Code: ---(setq ins1 (trans (cdr (assoc 10 (entget e1))) (cdr (assoc 210 (entget e1))) 1))
--- End code ---

A 2D entiy's OCS is calculated by AutoCAD regarding its extrusion direction (210 DXF code or Normal property) using an "arbitrary axis algorithm" (see "Advanced DXF concepts" in the DXF section of the Developper's guide).
You can calculate an entity's OCS using this code :


--- Code: ---;;; OCS Calculates the OCS of a 2D entity (text, block, circle, arc, lwpolyline, hatch ...)
;;; Argument : zdir, a single unit vector as returned by 210 DXF code
(defun sco (zdir / xdir)
  (if (and (< (abs (car zdir)) 0.015625)
   (< (abs (cadr zdir)) 0.015625)
      )
    (setq xdir (vunit (v^v '(0 1 0) zdir)))
    (setq xdir (vunit (v^v '(0 0 1) zdir)))
  )
  (list xdir (vunit (v^v zdir xdir)) zdir)
)

;;; VUNIT Returns the vector's single unit vector
;;; Argument : v, a vector
(defun vunit (v / l)
  (if (/= 0 (setq l (sqrt (apply '+ (mapcar '* v v)))))
    (mapcar '(lambda (x) (/ x l)) v)
  )
)

;;; V^V Returns the cross product of two vecors
;;; (the normal vector of the plane defined by v1 v2)
;;; Argument : v1 v2, two non-colinear vectors
(defun v^v (v1 v2)
  (if (inters '(0 0 0) v1 '(0 0 0) v2)
    (list (- (* (cadr v1) (caddr v2)) (* (caddr v1) (cadr v2)))
  (- (* (caddr v1) (car v2)) (* (car v1) (caddr v2)))
  (- (* (car v1) (cadr v2)) (* (cadr v1) (car v2)))
    )
    '(0.0 0.0 0.0)
  )
)
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version