UCS command not work

UCS command not work

saitoib
Advocate Advocate
1,047 Views
14 Replies
Message 1 of 15

UCS command not work

saitoib
Advocate
Advocate
Thank you for your help.

In Lisp, if each data is as follows
(command "UCS" mid pt2 pt2)
command does not work properly.

MID: (50.0 112.426 0.0)
PT2: (6.12323e-16 10.0 0.0)
PT3: (-10.0 1.22465e-15 0.0)

Is there a solution?
thank you.
Saitoib
0 Likes
1,048 Views
14 Replies
Replies (14)
Message 2 of 15

Sea-Haven
Mentor
Mentor

UCS 3 maybe, also e-16 is say to close to 0.0 

0 Likes
Message 3 of 15

Kent1Cooper
Consultant
Consultant

@saitoib wrote:
....
In Lisp, if each data is as follows
(command "UCS" mid pt2 pt2)
command does not work properly.

MID: (50.0 112.426 0.0)
PT2: (6.12323e-16 10.0 0.0)
PT3: (-10.0 1.22465e-15 0.0)

Is there a solution?
....

Have the last two points different from each other:

(command "UCS" mid pt2 pt3)

Kent Cooper, AIA
0 Likes
Message 4 of 15

saitoib
Advocate
Advocate
I'm sorry.
I made a copy and paste mistake.
(command "UCS" mid pt2 pt3)
is correct.
Saitoib
0 Likes
Message 5 of 15

saitoib
Advocate
Advocate
Afterwwards I thought the cause of the error might be the exponential value, so I rounded it to the fifth decimal place, but the result was the same.
Also, in case 1, I could set the UCS, but in case 2, I could not set, the message [Specify a point on the plane or <accept>] appears and the process does not proceed.
This error occurs when you try to set the UCS vertically.

Case 1
MID: (112.426 50.0 0.0)
PT2: (10.0 0.0 0.0)
PT3: (6.12323e-15 10.0 0.0)

Case 2
MID: (50.0 112.4264 0.0)
PT2: (2.83277e-15 10.0 0.0)
PT3: (-10.0 1.22465e-15 0.0)

Is there any way to deal with this?
Saitoib
0 Likes
Message 6 of 15

leeminardi
Mentor
Mentor

The following worked for me.

(defun c:test (/)
  (setq	mid '(112.426 50.0 0.0)
	PT2 '(10.0 0.0 0.0)
	PT3 '(6.12323e-15 10.0 0.0)
  )
  (command "UCS" mid PT2 PT3)
)

It is interesting to note that even though AutoCAD "only" has about 15 significant digits the precision of the mantissas in your data is limited to 6 digits so there should be no precision problems.  I don't think it would be a bad idea to change the "e-15" values to 0.0.  

lee.minardi
0 Likes
Message 7 of 15

saitoib
Advocate
Advocate

For example, with a shape like the following

rectang 0,0 100,100
rotate 45
fillet r 20
explode

 

 

(defun C:test1 (/ nn obj ent pnt ang1 ang2 ang cent mid radi
  									pt2 pt3 str tmp ostmp)

	(setq ent (entget (car (entsel))))
  
	(setq cent (cdr (assoc 10 ent)));center
	(setq radi (cdr (assoc 40 ent)));radius
	(setq ang1 (cdr (assoc 50 ent)));start angle
 	(setq ang2 (cdr (assoc 51 ent)));end angle

	(if (< ang2 ang1);start 270 end 0
		(setq ang2 (+ ang2 (* pi 2)))
	)
  (setq ang (+ ang1 (/ (- ang2 ang1) 2)));mid angle
 
	(setq mid (polar cent ang radi));mid point

	(setq str "Tset")
	
  ;Relative coordinate calculation
	(if (and (> ang (/ pi 2)) (<= ang (* (/ pi 2) 3)))
		(progn
  		(setq pt2 (polar '(0 0 0) (angle mid cent) 10))
			(setq pt3 (polar '(0 0 0) (- ang (/ pi 2)) 10))
		)
		(progn
			(setq pt2 (polar '(0 0 0) (angle cent mid) 10))
			(setq pt3 (polar '(0 0 0) (+ ang (/ pi 2)) 10))
		)
  )
  
	(setq ostmp (getvar "OSMODE"))
	(setvar "OSMODE" 0)
	(setvar "CMDECHO" 0)
	
	(command "_ucs" mid pt2 pt3)
	(command "_leader" '(0 0 0) PAUSE "_a" str "")
	(command "_ucs" "p")
	(setvar "OSMODE" ostmp)
	(setvar "CMDECHO" 1)
	
	(princ)
)

 

Saitoib
0 Likes
Message 8 of 15

CADaSchtroumpf
Advisor
Advisor

Why use UCS ?!

You can try this

(defun c:test ( / ent pt1 pt2 pt)
  (setq ent (entsel))
  (cond
    (ent
      (setq
        ent (car ent)
        pt1 (vlax-curve-getStartPoint ent)
        pt2 (vlax-curve-getEndPoint ent)
        pt (vlax-curve-getPointAtDist ent (* 0.5 (- (vlax-curve-getDistAtPoint ent pt2) (vlax-curve-getDistAtPoint ent pt1))))
      )
      (command "_leader" "_none" pt PAUSE "_a" "Test" "")
    )
  )
  (prin1)
)
0 Likes
Message 9 of 15

Sea-Haven
Mentor
Mentor

I am doing some stuff now with points on vertical walls and found osnapz will screw you right up must be set to 1.

 

I just use UCS 3 Pt1 PT2 (pt1 + a new Z value )

 

 

0 Likes
Message 10 of 15

saitoib
Advocate
Advocate

@CADaSchtroumpf 

In the case of the attached figure, I want to draw the top and bottom leader lines in 90 and 270 degree directions.

 

@Sea-Haven 

Setting the osnapz variable to 1 does not seem to make any difference.
Do you set the z-value to something other than 0?

 

Saitoib
0 Likes
Message 11 of 15

hencoop
Advisor
Advisor

You might try using "@x,y,z" for each axis input.

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 12 of 15

CADaSchtroumpf
Advisor
Advisor

If I understood your need correctly (this looks a lot like a radius dimension, why a leader line?)

(vl-load-com)
(defun make_mlead (pt o r obj / ptlst arr nw_obj)
  (setq
    ptlst (append pt (polar pt o r))
    arr (vlax-make-safearray vlax-vbdouble (cons 0 (- (length ptlst) 1)))
  )
  (vlax-safearray-fill arr ptlst)
  (setq nw_obj (vla-addMLeader Space (vlax-make-variant arr) 0))
  (vla-put-contenttype nw_obj acMTextContent)
  (vla-put-textstring nw_obj (strcat "{\\fArial|b0|i0|c0|p34;R=" (rtos r 2 2) "\\P\\C1You can put here other value}"))
  (vla-put-layer nw_obj (getvar "CLAYER"))
  (vla-put-ArrowheadSize nw_obj (* (getvar "TEXTSIZE") 0.5))
  (vla-put-TextHeight nw_obj (getvar "TEXTSIZE"))
  (if (> (car ptlst) (cadddr ptlst))
    (progn
      (vla-SetDogLegDirection nw_obj 0 (vlax-3D-point '(-1.0 0.0 0.0)))
      (vla-put-TextJustify nw_obj acAttachmentPointMiddleRight)
      (vla-setLeaderLineVertices nw_obj 0 (vlax-make-variant arr))
    )
    (vla-put-TextJustify nw_obj acAttachmentPointMiddleLeft)
  )
  (vla-update nw_obj)
)
(defun c:rad2lead ( / ent dxf_ent typ_ent mkv vector vlaobj prm id_rad AcDoc Space ent pt1 pt2 pt x)
  (while (not (setq ent (entsel "\nSelect a bulge: "))))
  (setq typ_ent (cdr (assoc 0 (setq dxf_ent (entget (car ent))))))
  (cond
    ((or
      (eq typ_ent "ARC")
      (eq typ_ent "CIRCLE")
      (eq typ_ent "LWPOLYLINE")
      (and
        (eq typ_ent "POLYLINE")
        (zerop (boole 1 120 (cdr (assoc 70 dxf_ent))))
      )
     )
      (if (or (> (fix (car (trans (cadr ent) 1 0))) 1E6) (> (fix (cadr (trans (cadr ent) 1 0))) 1E6))
        (setq mkv T vector (trans (cadr ent) 0 0 T) vlaobj (vlax-ename->vla-object (car ent)))
        (setq mkv nil)
      )
      (if mkv (vla-move vlaobj (vlax-3d-point (trans (cadr ent) 1 0)) (vlax-3d-point '(0.0 0.0 0.0))))
      (setq id_rad
        (distance
          '(0 0)
          (trans
            (vlax-curve-getsecondderiv (car ent)
              (setq prm
                (vlax-curve-getparamatpoint (car ent)
                  (vlax-curve-getclosestpointto (car ent) (if mkv '(0.0 0.0 0.0) (trans (cadr ent) 1 0)))
                )
              )
            )
            0
            (car ent)
            T
          )
        )
      )
      (if mkv (vla-move vlaobj (vlax-3d-point '(0.0 0.0 0.0)) (vlax-3d-point vector)))
      (cond
        ((not (zerop id_rad))
          (setq
            AcDoc (vla-get-ActiveDocument (vlax-get-acad-object))
            Space
            (if (= 1 (getvar "CVPORT"))
              (vla-get-PaperSpace AcDoc)
              (vla-get-ModelSpace AcDoc)
            )
          )
          (vla-startundomark AcDoc)
          (setq ent (car ent))
          (if (member typ_ent '("POLYLINE" "LWPOLYLINE"))
            (setq
              pt1 (vlax-curve-getPointAtParam ent (fix prm))
              pt2 (vlax-curve-getPointAtParam ent (1+ (fix prm)))
              pt (vlax-curve-getPointAtParam ent (+ (fix prm) 0.5))
            )
            (setq
              pt1 (vlax-curve-getStartPoint ent)
              pt2 (vlax-curve-getEndPoint ent)
              pt (vlax-curve-getPointAtDist ent (* 0.5 (- (vlax-curve-getDistAtPoint ent pt2) (vlax-curve-getDistAtPoint ent pt1))))
            )
          )
          (setq
            x (* (fix (/ (angle (mapcar '* (mapcar '+ pt1 pt2) '(0.5 0.5 0.5)) pt) (* 0.125 pi))) 0.125 pi)
            x (+ x (rem x (* 0.25 pi)))
          )
          (make_mlead pt x id_rad (vlax-ename->vla-object ent))
          (vla-regen AcDoc acactiveviewport)
          (vla-endundomark AcDoc)
        )
        (T (princ "\nSegment have no bulge."))
      )
    )
    (T (princ "\nThis object can't be availaible for this function!"))
  )
  (prin1)
)
0 Likes
Message 13 of 15

saitoib
Advocate
Advocate

@CADaSchtroumpf 

Sorry about that.
I think this is probably a local rule in my country.

I tried to run the UCS command from the command line, but it still didn't work for the vertical direction.
So, I guess this problem is not related to Lisp.

Thank you very much for all your help.
 
Saitoib
0 Likes
Message 14 of 15

hencoop
Advisor
Advisor

Have you checked whether your drawing is 2D or 3D?

AutoCAD User since 1989. Civil Engineering Professional since 1983
Product Version: 13.6.1963.0 Civil 3D 2024.4.1 Update Built on: U.202.0.0 AutoCAD 2024.1.6
                        27.0.37.14 Autodesk AutoCAD Map 3D 2024.0.1
                        8.6.52.0 AutoCAD Architecture 2024
0 Likes
Message 15 of 15

saitoib
Advocate
Advocate

@hencoop 

I'm drawing in 2D.

 

Saitoib
0 Likes