Author Topic: z move regardless of ucs lisp error problem  (Read 474 times)

0 Members and 1 Guest are viewing this topic.

dussla

  • Bull Frog
  • Posts: 297
z move regardless of ucs lisp error problem
« on: April 02, 2024, 02:21:40 AM »
hi firends
nice meet you .
i need some help .
i tested many times
but i can not  catch error


The solid is moved to a new ucs with only the z value set to 0.

error message :  error: bad argument type: fixnump: (0.0 0.0)

 can you help ~?
(defun c:zero (/ ss obj minPoint maxPoint movePt ucsOrigin minPointUCS maxPointUCS)

  (setq ss (ssget "_:L" '((0 . "3DSOLID")))) ; Select only single object

  (if (= (sslength ss) 1) ; Check if only one object is selected
      (progn
        (setq obj (ssname ss 0)) ; Use only the first selected object
       
        ; Get current UCS origin
        (setq ucsOrigin (getvar 'ucsorg))
       
        ; Prompt user to select a move point
        (setq movePt (getpoint "\nEnter the move point (Z value): "))
       
        ; Calculate Z-axis move distance in current UCS
        (setq deltaZ (- (caddr movePt) (caddr ucsOrigin)))
       
        ; Get the bounding box of the solid object
        (setq obj (vlax-ename->vla-object obj))
        (setq minPoint (vlax-make-safearray vlax-vbDouble '(0.0 0.0 0.0)))
        (setq maxPoint (vlax-make-safearray vlax-vbDouble '(0.0 0.0 0.0)))
       
        ; Try to get the bounding box
        (if (and (vla-getboundingbox obj minPoint maxPoint) minPoint maxPoint)
            (progn
              ; Get the minimum and maximum points in current UCS
              (setq minPointUCS (mapcar '+ (vlax-safearray->list minPoint) ucsOrigin))
              (setq maxPointUCS (mapcar '+ (vlax-safearray->list maxPoint) ucsOrigin))
             
              ; Move the solid object
              (vla-move obj (vlax-3d-point minPointUCS) (vlax-3d-point (list 0.0 0.0 deltaZ)))
            )
            (prompt "\nThe bounding box does not exist.")
        )
      )
  )

  (princ)
)
« Last Edit: April 03, 2024, 06:51:11 AM by dussla »

xdcad

  • Bull Frog
  • Posts: 495
Re: z move regardless of ucs lisp error problem
« Reply #1 on: April 02, 2024, 03:42:49 AM »
hi firends
nice meet you .
i need some help .
i tested many times
but i can not  catch error


The solid is moved to a new ucs with only the z value set to 0.

error message :  error: bad argument type: fixnump: (0.0 0.0)

 can you help ~?
(defun c:zero (/ ss obj minPoint maxPoint movePt ucsOrigin minPointUCS maxPointUCS)

  (setq ss (ssget "_:L" '((0 . "3DSOLID")))) ; Select only single object

  (if (= (sslength ss) 1) ; Check if only one object is selected
      (progn
        (setq obj (ssname ss 0)) ; Use only the first selected object
       
        ; Get current UCS origin
        (setq ucsOrigin (getvar 'ucsorg))
       
        ; Prompt user to select a move point
        (setq movePt (getpoint "\nEnter the move point (Z value): "))
       
        ; Calculate Z-axis move distance in current UCS
        (setq deltaZ (- (caddr movePt) (caddr ucsOrigin)))
       
        ; Get the bounding box of the solid object
        (setq obj (vlax-ename->vla-object obj))
        (setq minPoint (vlax-make-safearray vlax-vbDouble '(0.0 0.0 0.0)))
        (setq maxPoint (vlax-make-safearray vlax-vbDouble '(0.0 0.0 0.0)))
       
        ; Try to get the bounding box
        (if (and (vla-getboundingbox obj minPoint maxPoint) minPoint maxPoint)
            (progn
              ; Get the minimum and maximum points in current UCS
              (setq minPointUCS (mapcar '+ (vlax-safearray->list minPoint) ucsOrigin))
              (setq maxPointUCS (mapcar '+ (vlax-safearray->list maxPoint) ucsOrigin))
             
              ; Move the solid object
              (vla-move obj (vlax-3d-point minPointUCS) (vlax-3d-point (list 0.0 0.0 deltaZ)))
            )
            (prompt "\nThe bounding box does not exist.")
        )
      )
  )

  (princ)
)

HI, pls upload test dwg.
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
https://github.com/xdcad
https://sourceforge.net/projects/xdrx-api-zip/
http://bbs.xdcad.net

dussla

  • Bull Frog
  • Posts: 297
Re: z move regardless of ucs lisp error problem
« Reply #2 on: April 02, 2024, 03:50:30 AM »
thank you
i uploaded file

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: z move regardless of ucs lisp error problem
« Reply #3 on: April 02, 2024, 05:24:14 AM »
This syntax is incorrect -
Code - Auto/Visual Lisp: [Select]
  1. (vlax-make-safearray vlax-vbDouble '(0.0 0.0 0.0))

Per the documentation, the second argument represents the index bounds of the safearray, and should be a dotted pair of integers, hence something like:

Code - Auto/Visual Lisp: [Select]
  1. (vlax-make-safearray vlax-vbDouble '(0 . 2))

However, these two expressions can be commented entirely, as the getboundingbox method performs the initialisation of the safearrays.

ribarm

  • Gator
  • Posts: 3279
  • Marko Ribar, architect
Re: z move regardless of ucs lisp error problem
« Reply #4 on: April 02, 2024, 08:16:42 AM »
According to the posted drawing, you are moving box to touch 0.0 UCS elevation... Will this be always the case? You have to explain more what do you want... You can simply pick a point, say lowest point of face of 3DSOLID looked from UCS and according to DWG just use command MOVE from picked pt to (list (car pt) (cadr pt) 0.0)... Does it have some sense now?
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

dussla

  • Bull Frog
  • Posts: 297
Re: z move regardless of ucs lisp error problem
« Reply #5 on: April 02, 2024, 09:01:08 AM »
According to the posted drawing, you are moving box to touch 0.0 UCS elevation... Will this be always the case? You have to explain more what do you want... You can simply pick a point, say lowest point of face of 3DSOLID looked from UCS and according to DWG just use command MOVE from picked pt to (list (car pt) (cadr pt) 0.0)... Does it have some sense now?


thank you~

My work order is as follows
1. I change ucs for example
Like this

(defun c:4f()
(command "ucs" "w" )
(command "ucs" "x" "90" )


)


(defun c:4r()
(command "ucs" "w" )
(command "ucs" "x" "90" )
(command "ucs" "y" "90" )


)


(defun c:4b()
(command "ucs" "w" )
(command "ucs" "z" "180" )
(command "ucs" "x" "90" )


)



(defun c:4l()
(command "ucs" "w" )
(command "ucs" "x" "90" )
(command "ucs" "y" "-90" )


)


2. If I change ucs, the z axis of the square box will also be converted.
My goal is to move the minimum z position value of the changed coordinates of the box to the selected point.




in 2d object , this code work well , but  solid not work
(defun c:4z(/ act_doc ss yt1 py1 newss index ent1 ele dist-ed pt  )
    (setvar "osmode" 35  )
   (setq adoc (vla-get-activedocument  (vlax-get-acad-object) )   acsp (vla-get-block  (vla-get-activelayout adoc))      )
   (UndoBegin adoc)
(setq oldec (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 
 (setq p1 (getpoint "\n ucs z  point :"))
 (command "ucs" "za" p1 "" )

 (setq ss (ssget))
   (cadr (sssetfirst nil ss))
 (setvar "osmode" 0  )
 
       (setq  newss (ssadd))
   (setq index 0)
   (repeat (sslength ss)
             (setq ent1 (ssname ss index))
           
          (command "change" ent1 "" "P"  "el" "0" "")
             (setq index (+ index 1 ))
   )
   
      (UndoEnd adoc)
      (setvar "osmode" 35 )
      ;(command "ucs" "w")
      (princ)
      
   
      
)
« Last Edit: April 02, 2024, 09:07:11 AM by dussla »

dussla

  • Bull Frog
  • Posts: 297
Re: z move regardless of ucs lisp error problem
« Reply #6 on: April 02, 2024, 09:06:40 AM »
This syntax is incorrect -
Code - Auto/Visual Lisp: [Select]
  1. (vlax-make-safearray vlax-vbDouble '(0.0 0.0 0.0))

Per the documentation, the second argument represents the index bounds of the safearray, and should be a dotted pair of integers, hence something like:

Code - Auto/Visual Lisp: [Select]
  1. (vlax-make-safearray vlax-vbDouble '(0 . 2))

However, these two expressions can be commented entirely, as the getboundingbox method performs the initialisation of the safearrays.

thank you for good advice

dussla

  • Bull Frog
  • Posts: 297
Re: z move regardless of ucs lisp error problem
« Reply #7 on: April 02, 2024, 10:26:41 PM »
i made this code with gpt
but still ,
For solid objects, only the z value does not change relative to the current ucs, but the x and y values ​​also change.
Why?

(defun UCS2WCSMatrix ()
  (vlax-tmatrix
    (append
      (mapcar
        '(lambda (vector origin)
           (append (trans vector 1 0 t) (list origin))
         )
        (list '(1 0 0) '(0 1 0) '(0 0 1))
        (trans '(0 0 0) 0 1)
      )
      (list '(0 0 0 1))
    )
  )
)

(defun WCS2UCSMatrix ()
  (vlax-tmatrix
    (append
      (mapcar
        '(lambda (vector origin)
           (append (trans vector 0 1 t) (list origin))
         )
        (list '(1 0 0) '(0 1 0) '(0 0 1))
        (trans '(0 0 0) 1 0)
      )
      (list '(0 0 0 1))
    )
  )
)
(defun c:z99 (/ boxe EAboxn minpoint minpt maxpoint maxpt oscmd minZPoint selPointUCS originalX originalY)
  (setq oscmd (getvar "osmode"))
  (setvar "osmode" 0)

  ;; Get the 3DSolid object
  (setq boxe (car (entsel "\nPick 3DSolid object to check its lowest height in current UCS")))
  (setq EAboxn (vlax-ename->vla-object boxe))

  ;; Get the target point
  (setq selPoint (getpoint "\nPick a target point to move the solid's lowest Z value to: "))

  ;; Convert the target point to UCS coordinates
  (setq selPointUCS (trans selPoint 1 0))

  ;; Get the bounding box of the 3DSolid object
  (vla-TransformBy EAboxn (UCS2WCSMatrix))
  (vla-getboundingbox EAboxn 'minpoint 'maxpoint)
  (setq originalX (car (vlax-safearray->list minpoint)))
  (setq originalY (cadr (vlax-safearray->list minpoint)))
  (vla-TransformBy EAboxn (WCS2UCSMatrix))

  ;; Get the lowest point height of the 3DSolid object in current UCS
  (setq minpt (vlax-safearray->list minpoint))
  (prompt "\nLowest point height of 3DSolid object in current UCS is: ")
  (princ (caddr minpt))

  ;; Move the solid to the selected point's Z value, keeping x and y unchanged
  (setq minZPoint (list originalX originalY (caddr minpt)))

  ;; Perform the move operation
  (if minZPoint
    (progn
      (vla-TransformBy EAboxn (UCS2WCSMatrix))
      (vla-move EAboxn (vlax-3d-point minZPoint))
      (vla-TransformBy EAboxn (WCS2UCSMatrix))
      (prompt "\nSolid moved successfully.")
    )
    (prompt "\nNo point selected. Solid not moved.")
  )

  ;; Restore the OSMODE system variable
  (setvar "osmode" oscmd)
  (princ)
)