TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: dussla on April 27, 2024, 03:00:46 AM

Title: solid face copy ucs problem
Post by: dussla on April 27, 2024, 03:00:46 AM
hello friend
Thankfully I am testing rjp's code

I found that if I copy the face from the solid, the z value of the ucs is flipped 180 degrees.
So I applied the following code     (command "ucs" "z" "180" "")
But still the z values ​​are not flipped 

do you know problem ?


(defun c:bbb (/ a b e p )
  ;; RJP ≫ 2019-01-30
  (setvar "osmode" 0) ; Set 'osmode' variable to 0
  (while (setq p (getpoint "\nPick a point in a face: ")) ; Repeat until user picks a point
    (setq a (entlast)) ; Store the last entity created, presumably a face
    (vl-cmdf "_.Solidedit" "_Face" "_Copy" p "" '(0 0 0) '(0 0 0) "" "") ; Copy the face
    (cond
      ((eq a (setq e (entlast))) (print "Boundary not created..")) ; If no boundary created
      ((/= "REGION" (cdr (assoc 0 (entget e)))) (entdel e) (print "Boundary created not valid..")) ; If created boundary is not valid
      ((setq b (vlax-invoke (vlax-ename->vla-object e) 'explode)) ; If boundary is valid, explode it
       (command "_.ucs" "_OB" (vlax-vla-object->ename (car b))) ; Set UCS to object
       (mapcar 'vla-delete b) ; Delete exploded objects
       (command "ucsicon" "or" "") ; Turn UCS icon to original position
      (command "ucs" "z" "180" "") ; Rotate UCS by 180 degrees
       (command "UCSICON" "ON"))) ; Turn on UCS icon
    ) ; End of while loop
  ) ; End of defun
Title: Re: solid face copy ucs problem
Post by: ribarm on April 27, 2024, 06:49:48 AM
Have you tried to remove all "UCS" statements from *.lsp and leave only one with alignment to REGION face...
Something like this :

Code: [Select]
(defun c:bbb (/ *error* o a e p )
  ;; RJP ≫ 2019-01-30
  ;; mod. M.R.

  (defun *error* ( m )
    (if o
      (setvar (quote osmode) o)
    )
    (if m
      (prompt m)
    )
    (princ)
  )

  (setq o (getvar (quote osmode)))
  (setvar (quote osmode) 0) ; Set 'osmode' variable to 0
  (while (setq p (getpoint "\nPick a point in a face : ")) ; Repeat until user picks a point
    (setq a (entlast)) ; Store the last entity created, presumably a face
    (vl-cmdf "_.Solidedit" "_Face" "_Copy" p "" (list 0.0 0.0 0.0) (list 0.0 0.0 0.0) "" "") ; Copy the face
    (cond
      ( (eq a (setq e (entlast))) (print "Boundary not created..") ) ; If no boundary created
      ( (/= "REGION" (cdr (assoc 0 (entget e)))) ; If created boundary is not valid
        (print "Boundary created not valid..")
      )
      ( t
        (vl-cmdf "_.ucs" "_OB" e) ; created boundary is REGION and UCS aligned to it
      )
    ) ; End of cond
    (if (not (eq a e))
      (while (setq a (entnext a))
        (if (and a (not (vlax-erased-p a)))
          (entdel a)
        )
      ) ; Delete REGION or not valid boundary created after (setq a (entlast))
    ) ; End of if
  ) ; End of while loop
  (*error* nil)
) ; End of defun
Title: Re: solid face copy ucs problem
Post by: dussla on April 27, 2024, 07:42:32 AM
Thanks for the reply.

Removing the UCS icon is not what I want.
After copying a face from a solid, the generated UCS will have Y+ facing down.
I want the UCS to always have Y facing up after being copied.

for the next task
Title: Re: solid face copy ucs problem
Post by: ribarm on April 27, 2024, 08:52:11 AM
I've changed the code slightly to remove REGION after face is beeing copied...
I don't know how do you get 'ucsydir not aligned to edge of face - region... Both X and Y should be aligned to edges and Z with normal axis from inner to outer of 3dsolid...
Title: Re: solid face copy ucs problem
Post by: dussla on April 27, 2024, 09:24:54 AM
I've changed the code slightly to remove REGION after face is beeing copied...
I don't know how do you get 'ucsydir not aligned to edge of face - region... Both X and Y should be aligned to edges and Z with normal axis from inner to outer of 3dsolid...

really thank you your effort
i tested modified code

but still  not work


pls see result attachef file
still  y  down
Title: Re: solid face copy ucs problem
Post by: ribarm on April 27, 2024, 09:28:36 AM
Look, I am using BricsCAD and whereever I pick point on 3dsolid - BOX my both X and Y axises are aligned to edges of BOX... Haven't tested it with AutoCAD - give me a minute to try...
Title: Re: solid face copy ucs problem
Post by: dussla on April 27, 2024, 09:32:42 AM
Look, I am using BricsCAD and whereever I pick point on 3dsolid - BOX my both X and Y axises are aligned to edges of BOX... Haven't tested it with AutoCAD - give me a minute to try...

ok thank you   for your effort

i wil try ~
Title: Re: solid face copy ucs problem
Post by: ribarm on April 27, 2024, 09:37:47 AM
It seems that AutoCAD is buggy with this code... In BricsCAD it alignes UCS to region and in AutoCAD it reports that this object don't define coordinate system... And to be even more buggy it doesn't remove created regions after solidedit - copy - face options...
Title: Re: solid face copy ucs problem
Post by: dussla on April 27, 2024, 09:44:47 AM
It seems that AutoCAD is buggy with this code... In BricsCAD it alignes UCS to region and in AutoCAD it reports that this object don't define coordinate system... And to be even more buggy it doesn't remove created regions after solidedit - copy - face options...
Thank you, I learned a lot of information from you.
Title: Re: solid face copy ucs problem
Post by: ribarm on April 27, 2024, 01:08:02 PM
Here @dussla, try with this mod...
Should work well in both AutoCAD and BricsCAD...

Code - Auto/Visual Lisp: [Select]
  1. (defun c:bbb (/ *error* getlinvetices unique c o p a e v )
  2.   ;; RJP ≫ 2019-01-30
  3.   ;; mod. M.R.
  4.  
  5.  
  6.   (defun *error* ( m )
  7.     (if o
  8.       (setvar (quote osmode) o)
  9.     )
  10.     (if c
  11.       (setvar (quote cmdecho) c)
  12.     )
  13.     (if m
  14.       (prompt m)
  15.     )
  16.     (princ)
  17.   )
  18.  
  19.   (defun getlinvetices ( e / x )
  20.     (list (cdr (assoc 10 (setq x (entget e)))) (cdr (assoc 11 x)))
  21.   )
  22.  
  23.   (defun unique ( l )
  24.     (if l
  25.       (cons (car l)
  26.         (unique
  27.           (vl-remove-if
  28.             (function
  29.               (lambda ( x ) (equal x (car l) 1e-6))
  30.             )
  31.             (cdr l)
  32.           )
  33.         )
  34.       )
  35.     )
  36.   )
  37.  
  38.   (setq c (getvar (quote cmdecho)))
  39.   (setvar (quote cmdecho) 0) ; Set 'cmdecho' variable to 0
  40.   (setq o (getvar (quote osmode)))
  41.   (setvar (quote osmode) 0) ; Set 'osmode' variable to 0
  42.   (while (setq p (getpoint "\nPick a point in a face : ")) ; Repeat until user picks a point
  43.     (setq p (trans p 1 0))
  44.     (vl-cmdf "_.ucs" "_w") ; Set 'ucs' to 'worlducs'
  45.     (setq a (entlast)) ; Store the last entity created, presumably a face
  46.     (vl-cmdf "_.Solidedit" "_Face" "_Copy" p "" (list 0.0 0.0 0.0) (list 0.0 0.0 0.0) "" "") ; Copy the face
  47.     (cond
  48.       ( (eq a (setq e (entlast))) (print "Boundary not created..") ) ; If no boundary created
  49.       ( (/= "REGION" (cdr (assoc 0 (entget e)))) ; If created boundary is not valid
  50.         (print "Boundary created not valid..")
  51.       )
  52.       ( t ; If created boundary is valid REGION
  53.         (vl-cmdf "_.explode" e)
  54.         (setq v nil)
  55.         (while (setq e (entnext e))
  56.           (setq v (append v (getlinvetices e)))
  57.           (if (and e (not (vlax-erased-p e)))
  58.             (entdel e)
  59.           )
  60.         )
  61.         (setq v (unique v))
  62.         (vl-cmdf "_.ucs" "_3p" (car v) (cadr v) (caddr v)) ; UCS is aligned to face
  63.       )
  64.     ) ; End of cond
  65.     (if (not (eq a e))
  66.       (while (setq a (entnext a))
  67.         (if (and a (not (vlax-erased-p a)))
  68.           (entdel a)
  69.         )
  70.       ) ; Delete REGION or not valid boundary created after (setq a (entlast))
  71.     ) ; End of if
  72.   ) ; End of while loop
  73.   (*error* nil)
  74. ) ; End of defun
  75.  

HTH.
M.R.
Title: Re: solid face copy ucs problem
Post by: dussla on April 27, 2024, 09:28:15 PM
It works so well
thank thank Thank you so much for your help so far.
But I found one problem.
I'm not very good at it, so I'm asking the question again.
This does not work for objects with joined solids.

So I came up with the following idea:
what do you think?
Still, implementing this in code is too difficult for me