Jump to content

How to pass an entity into the area command as object selection?


Recommended Posts

Posted

Hello, I have a simple drawing with a few enclosed polylines. I am trying to use the area function to compute their areas. My code looks like this:

 

  ;prompt user to select all polylines to compute area in one go.

  (setq ss (ssget))

  (setq tot (sslength ss))

 

  ;get total area of all spaces

  (setq areaTot 0)

  (setq iter 0)

  (while (< iter tot)

    (setq space (entget (ssname ss iter)))

    (command "area" "o" space)        <<------This line is obviously the problem

    (setq areaTot (+ areaTot (getvar "area")))

    (setq iter (+ iter 1))

  )

  (print areaTot)

 

But clearly this doesn't work, as area function is expecting an "object" input while I'm giving it an entity. But what data format is it looking for exactly? How to make entity an object? Thank you.

Posted

Weclome to CADTutor :)

;; Change this
(setq space (entget (ssname ss iter)))
(command "area" "o" space)
(setq areatot (+ areatot (getvar "area")))
;; To this
(setq space (ssname ss iter))
(setq areatot (+ areatot (vlax-curve-getarea space)))

 

  • Thanks 1
Posted
3 hours ago, ronjonp said:

Weclome to CADTutor :)

;; Change this
(setq space (entget (ssname ss iter)))
(command "area" "o" space)
(setq areatot (+ areatot (getvar "area")))
;; To this
(setq space (ssname ss iter))
(setq areatot (+ areatot (vlax-curve-getarea space)))

 

Thank you ronjonp, that works great. I am looking into vlax now because of your answer and that seems to unlock a whole new world of functionalities! 

Posted (edited)

You should also put in a filter for the objects selected. If you select a block the code will fail on vlax-curve-getarea.

Something like this:

(setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,*POLYLINE,REGION,SPLINE"))))

 

Edited by ronjonp
Posted
2 hours ago, ronjonp said:

You should also put in a filter for the objects selected. If you select a block the code will fail on vlax-curve-getarea.

Something like this:

(setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,*POLYLINE,REGION,SPLINE"))))

 

Thank you for that!

Posted
4 minutes ago, Reaper_of_Lykos said:

Thank you for that!

Not a problem! 👍

Posted (edited)
Quote

(setq ss (ssget '((0 . "ARC,CIRCLE,ELLIPSE,*POLYLINE,REGION,SPLINE"))))

 

Hi ronjonp, one follow up question I hope to ask is, what does the * before POLYLINE do? Thank you!

Edited by Reaper_of_Lykos
Posted
3 minutes ago, Reaper_of_Lykos said:

Hi ronjonp, one follow up question I hope to ask is, what does the * before POLYLINE do? Thank you!

It grabs lightweight polylines( LWPOLYLINE ) and 'heavy' 2D polylines ( POLYLINE ). Look at the objects listed in light blue HERE.

Posted

Use dumpit to see VL properties one of those must have programs.

 

;;;===================================================================; 
;;; DumpIt                                                            ; 
;;;-------------------------------------------------------------------; 
;;; Dump all methods and properties for selected objects              ; 
;;;===================================================================; 
(defun C:Dumpit ( / ent) 
  (while (setq ent (entsel)) 
    (vlax-Dump-Object 
      (vlax-Ename->Vla-Object (car ent)) 
    ) 
  ) 
  (princ) 
)

also

(defun c:entdump ()
(entget (car (entsel "\Pick object ")))
)

 

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