Jump to content

Recommended Posts

Posted

 

I have found the relevant lisp by Gruru Lee Mac, however, there is error msg "Region is not on the UCS plane: popped out for some object and I found that can be solved by converting the UCS as the object before creating the point at centroid of the polyline by the Lisp. May I ask is it possible to include the UCS command in the Lisp for each object? Greatly appreciate if any Master can help!
 

(defun c:pc ( / acdoc acspc acsel reg ) (vl-load-com) ;; £ Lee Mac 2011
 
 (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))
       acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace))
 )
 (if (ssget '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1)))
   (progn
     (vlax-for obj (setq acsel (vla-get-ActiveSelectionSet acdoc))
       (vlax-invoke acspc 'addpoint
         (trans (vlax-get (setq reg (car (vlax-invoke acspc 'addregion (list obj)))) 'Centroid) 1 0)
       )
       (vla-delete reg)
     )
     (vla-delete acsel)
   )
 )
 (princ)
)


Also I find the command for converting the UCS 

 
(defun c:obrotucs ( )
(command "ucs" "ob" pause "plan"
"current")
(princ)
)
 
Posted (edited)

The other way is to just work out the centroid from the vertice points, I think it was Gille that has a good one. 

 

Lee's code  has a trans function that should handle the ucs function sure he will answer.

 

Or 

;; Polygon Centroid  -  Lee Mac
;; Returns the WCS Centroid of an LWPolyline Polygon Entity

Edited by BIGAL
Posted

Consider the following code:

(defun c:pc ( / ent flg idx ocs reg sel spc ucs )    
    (if (setq sel (ssget '((0 . "LWPOLYLINE") (-4 . "&=") (70 . 1))))
        (progn
            (setq ucs (trans '(0 0 1) 1 0 t)
                  spc (vlax-get-property
                          (vla-get-activedocument (vlax-get-acad-object))
                          (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace)
                      )
            )
            (repeat (setq idx (sslength sel))
                (if (setq idx (1- idx)
                          ent (ssname sel idx)
                          ocs (assoc 210 (entget ent))
                          flg (not (equal (cdr ocs) ucs 1e-8))
                    )
                    (vl-cmdf "_.ucs" "_ob" ent)
                )
                (if (vl-catch-all-error-p
                        (setq reg
                            (vl-catch-all-apply 'vlax-invoke
                                (list spc 'addregion (list (vlax-ename->vla-object ent)))
                            )
                        )
                    )
                    (princ (strcat "\nError creating region: " (vl-catch-all-error-message reg)))
                    (progn
                        (entmake (list '(0 . "POINT") (cons 10 (trans (vlax-get (car reg) 'centroid) 1 0)) ocs))
                        (foreach obj reg
                            (if (vlax-write-enabled-p obj) (vla-delete obj))
                        )
                    )
                )
                (if flg (vl-cmdf "_.ucs" "_p"))
            )
        )
    )
    (princ)
)
(vl-load-com) (princ)

 

  • 4 years later...
Posted (edited)

Why the size of the circles got changed every time when the screen got zoomed in/out?

 

Edited by Wan
Posted

The centre of the polyline is marked by a point, I assume the circle is your point style?

 

Use the command ptype to adjust the point style, your point can be relative (the size changes as you zoom) or absolute (it won't change, gets bigger or smaller as you zoom) - set it to absolute and it will stay the same

  • Like 1
  • Agree 1

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...