Jump to content

Recommended Posts

Posted (edited)

If a 3dsolid isn't selected, this error happens:

[ActiveX Server returned the error: unknown name: "CENTROID"]

How can I filter entity before..

 

(defun c:scp (/  *error* p cnt lfw fa cen s oldOs oldUcs s)
  (vl-load-com)
  (princ "\n Center POint of 3DSolid Face <not.edge !pp>  ")

 (defun *error* ( msg )
(setvar 'cmdecho 0) ;; 5.28.24
  (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
  (if msg (prompt (strcat "\n" msg)))
    (command "._UCS" "_P") ;; Restore UCS
    (setvar 'osmode oldOs)
  (setvar 'cmdecho 1)    
  (princ)
)
  
;;   (setenv "pp" pp) ;; saved coords if/when crash
 (setq cnt 0)
  (setq oldOs (getvar 'osmode))
  (setq oldUcs (getvar 'ucsname))

  (setvar 'osmode 0)
 (setvar 'cmdecho 0) ;; 5.28.24
 (command "._UCS" "_W")
  
  ;;//---  BIGAL  ---;; https://www.cadtutor.net/forum/topic/24751-timing/#findComment-199009
(defun ddelay (d / cd);;; (ddelay 1e-6)  = 1 Second
     (setq cd (getvar "CDATE")) 
     (while (> (+ cd d)
     (getvar "CDATE")))
   )
 ;; <--- deselects 'sssetfirst'
	(defun ftp nil
	(setq pp             ;;  makes coords copy/paste usable
	   (strcat
	            (rtos (car s) 2 4) ","
	          (rtos (cadr s) 2 4) ","
	        (rtos (caddr s) 2 4) 
	      )
	)
	)
  (while (princ (strcat "\nFaces: " (itoa cnt) " | Pick face center: "))
;;; 
    (setvar 'osmode 0)

    ;; 1. Align UCS to the face so Centroid is "on the plane"
    ;;;(command "._UCS" "_N" "_Face" p "")
    ;;(if (not 
      (command "._UCS" "_n" "_Face" "\\" "")
      ;;(c:scp)))
   (setq cnt (1+ cnt))
  (setq p (getvar 'lastpoint))
  
    
    ;; 2. Copy the face in the local UCS
    (vl-cmdf "._SOLIDEDIT" "_F" "_C" p "" "0,0,0" "0,0,0" "" "")
    
    (setq lfw (entlast))
    (if (and lfw (setq fa (vlax-ename->vla-object lfw)))
      (progn
        ;; 3. Get Centroid (now valid because it's on current XY plane)
        (setq cen (vlax-get fa (quote centroid)))
        
        ;; 4. Convert UCS point to World coordinates for entmake
        (setq s (trans cen 1 0))
     (FTP)
        

   (sssetfirst nil (ssget "_L")) ;;) ;;highlights entity or: (ssadd ent (ssadd))) ;;; spf
   (setvar 'grips 0)
     (redraw) ;; <- usually required to show..
      (ddelay 5e-7) ;; allows 'shorter.times' <larger #'s = longer>
   (setvar 'grips 1)
    (sssetfirst nil nil)
        
        (entmake (list (cons 0 "POINT") (cons 10 s)))
          
       (if (not (vlax-erased-p fa))(vla-delete fa))
   
       (princ "\n")
        (princ PP) ;; print center coords
      )
      (princ "\nFailed to capture face.")
    )
    
    ;; Restore World to pick next face correctly
     (setvar 'cmdecho 0)
     (command "._UCS" "_W")
    (setvar 'osmode oldOs)
   ) ;; end of while

  ;; Final Cleanup
  (if (/= oldUcs "") (command "._UCS" "_N" oldUcs) (command "._UCS" "_W"))
 (setvar 'cmdecho 1) 
 (*error* nil)
  (princ)
)

 

Any suggestions would be great..

Edited by ScottMC
Posted

Another optn if possible would be using lines made to show cursor location

..when modifying pickbox size, it gets hard to see/find it. Thanks

Posted

A couple of suggestions.

 

(command "._UCS" "_P") ;; Restore UCS

(command "._UCS" "_R" ucsname) ;; Restore UCS incase have more than one UCS

Face

;; 1. Align UCS to the face so Centroid is "on the plane"
    ;;;(command "._UCS" "_N" "_Face" p "")
    ;;(if (not 
    ;  (command "._UCS" "_n" "_Face" "\\" "")


(command "._UCS" "_Face" pause "")
(command "UCS" "S" (getstring "\nEnter UCSs face name "))

 

Need to look more at your while, it does not make much sense to me, maybe like this.

 

(setq doagain "yes")

(while (= doagain "yes")

............ lots of code

(setq doagains (getstring "\Press any key to esxit Enter to do again "))
(if (= doagains "")
(princ)
(setq doagain doagains)
)
) ; end of while

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...