Making a tool to report Polyline areas, area variable gets stuck.

Making a tool to report Polyline areas, area variable gets stuck.

paul.disney
Contributor Contributor
670 Views
4 Replies
Message 1 of 5

Making a tool to report Polyline areas, area variable gets stuck.

paul.disney
Contributor
Contributor

I'm writing a tool to write the areas of polylines to an attribute block, but the area variable gets stuck on the first polyline.  Not sure how to properly clear that variable out for the next time the tool is run.  Anybody have experience working with the area command and the area variable?

Area Stuck.png

 

 

0 Likes
Accepted solutions (1)
671 Views
4 Replies
Replies (4)
Message 2 of 5

Kent1Cooper
Consultant
Consultant
Accepted solution

This may not be the cause of the exact problem you describe, but I notice this:

  ....

  (setq ent (entget (car ep))) ;; The Entity by name. ;;; <-- NO, IT'S AN ENTITY DATA LIST
  ;; (princ "\nTotal Area = ")
  (command "._area" "O" ent)
  (setq AreaString (getvar "area"))

  ....

The AREA command's Object option wants to be given an object, that is, an entity name.  But the 'ent' variable holds the result of (entget), which is an entity data list.  I think you want:

(setq ent (car ep)) ;; The Entity by name.

and put the entity data list into another variable for where 'ent' is used later in connection with the Layer.

 

Also, the 'AreaString' variable will be a number, not a text string, because you have "commented out" the line that would convert it to a string for use in assigning to the Attribute.

Kent Cooper, AIA
0 Likes
Message 3 of 5

paullimapa
Mentor
Mentor

In addition to @Kent1Cooper solutions, I would also recommend the following:

Consider using a selection filter to only select Plines that are closed using this code:

;;	CLICK ON CLOSED POLYLINE
  (while (not ep)
   (princ"\nPick a Closed Polyline...")
   (setq ep (ssget "_+.:E:S" '((0 . "POLYLINE,LWPOLYLINE") (-4 . "&") (70 . 1)))) ;; restrict selection
  )

Then when the desired entity is selected use the following code to get the entity and entity data:

  (if ep ; after valid entity is selected
   (progn ; then do the following
;; get Entity name
    (setq en (ssname ep 0))
;; get Entity data
    (setq ent (entget en))

Instead of using Area command and system variable to get the Pline's area, use a Field so that whenever the Pline changes the area string will update automatically:

;;;---load vl functions
 (if(not(car (atoms-family 1 '("vl-load-com"))))(vl-load-com))
; Get-ObjectIDx64 given object return object ID 
 (defun Get-ObjectIDx64 (obj / util)
  (setq util (vla-get-Utility (vla-get-activedocument (vlax-get-acad-object))))
  (if (= (type obj) 'ENAME)(setq obj (vlax-ename->vla-object obj)))
  (if (= (type obj) 'VLA-OBJECT)
    (if (> (vl-string-search "x64" (getvar "platform")) 0)
      (vlax-invoke-method util "GetObjectIdString" obj :vlax-False)
      (rtos (vla-get-objectid obj) 2 0)
    )
  )
 ) ; defun Get-ObjectIDx64 
;;  force fieldeval to be 31 so Fields will update after regen, save, plot and etc
    (if(/= 31 (getvar"fieldeval"))(setvar"fieldeval"31))
;; Convert Area to Square Feet vs Square Inch 
;; (princ "\nTotal Area = ")
;; (command "._Area" "_O" en)
;; (setq AreaString (getvar "area"))
;;  Use Fields to link pline area
;; for square feet use this
;        (setq AreaString (strcat (rtos (/ AreaString (* 12 12)) 2 2) " FT" (chr 178))) ;; Limit significant digits to max. 2
        (setq AreaString
         (strcat 
          "%<\\AcObjProp.16.2 Object (%<\\_ObjId " 
          (Get-ObjectIDx64 (vlax-ename->vla-object en)) 
          ">%).Area \\f \"%lu2%pr2%ps[, Ft" 
          (chr 178) 
          "]%ct8[0.0069444444444444]%th44\">%"
         )
        )
;; for square inch use this        
;        (setq AreaString (strcat (rtos AreaString 2 2) " Inch" (chr 178))) ;;	Limit significant digits to max. 2
        (setq AreaString
         (strcat 
          "%<\\AcObjProp.16.2 Object (%<\\_ObjId " 
          (Get-ObjectIDx64 (vlax-ename->vla-object en)) 
          ">%).Area \\f \"%lu2%pr2%ps[, Inch" 
          (chr 178) 
          "]%th44\">%"
         )
        )

 For the zone tag placement, consider initially using the current view center point for Insert and then end with the Move command so you can actually see the zone tag on the screen:

(setq ip (getvar"viewctr"))
;;	INSERTS ZONE TAG BLOCK
    (command "_.Insert" "ZONE AREA TAG" ip 1 1 0 AreaString ZoneName)			;;  Inserts a fitting at the specified scale and location.
(setq dragmode (getvar "dragmode")) ; save current dragmode setting
(setvar "dragmode" 2) ; set to 2
;; Reposition inserted block 
    (princ "\nPlace the Zone Tag: ")
    (command "_.Move" "_L" "" ip pause)
(setvar "dragmode" dragmode) ; restore setting

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 5

paul.disney
Contributor
Contributor

It looks like using (setq ent (entget (car ep))) WAS the issue, the Area command could grab the area of that data list, but then it gets stuck.  When I feed just the entity name to it, the command runs fine for any number of uses.  Attached is the revised tool (in its bare-bones form).  I'll add more functionality to it later, this is just a proof of concept for a set of engineering tools I want to develop.

 
0 Likes
Message 5 of 5

paullimapa
Mentor
Mentor

it crashes because you revised the code here for ent to be an entity name:

	(setq ent (car ep))	;;	The Entity by name.

 

but then later at this point of the code you're trying to get the assoc 8 pair of an entity data:

	(setq newlay (assoc 8 ent))								

 

but ent is still only an entity name. so to get the entity data you'll need to revise this section to look like this:

	(setq newlay (assoc 8 (entget ent)))								;;  Layer of the line the user first clicked on.

Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes