Jump to content

Recommended Posts

Posted

First post so please go easy if I'm posting in wrong forum.

 

Basically, I'm trying to find a way to write a script to state the length against all open polyines and state the area inside all closed polylines in one macro.  I've found a macro for each task but have no idea how to combine them.  I also need the length/area tex to be on the same layer as the line they reference.

 

Something like the below as I need to take of lots of information from plans and constantly clicking a line and then looking at the properties and copying to Excel is very time consuming.

 

image.png.77d939cd5ea9958c137a516ce53a6355.png

 

Any assistance would be much appreciated.  Thanks.

Posted

Post the 2 LISPs that you have if you are happy that they work OK (saves us time showing you others that you'd want to evaluate and check), am sure that combining them will be fairly easy

 

How do you copy to excel? It is also possible to put the output to clipboard to paste into a spreadsheet or make them up as a CSV file, or something to automate that... someone will have something handy to do that I think (I don't tend to do that but others do)

Posted

Post a dwg as well need your dwg to see what is made now.

Posted

thanks chaps.  I managed to get an answer on another forum but appreciate your assistance. 

Posted
(vl-load-com)

(defun c:PLenarea  (/ spc doc s i l e o vrs pts oid pnt fld txt)
  
  (setq spc (vla-get-modelspace (setq doc (vla-get-activedocument (vlax-get-acad-object)))))
  (vla-startundomark doc)
  
  (if (setq s (ssget '((0 . "CIRCLE,LWPOLYLINE,LINE,ARC"))))
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i)))
	    o (vlax-ename->vla-object e)
	    l (cdr (assoc 8 (entget e))))
      (if (or (= "CIRCLE" (cdr (assoc 0 (entget e))))
	      (and (= "LWPOLYLINE" (cdr (assoc 0 (entget e))))
		   (= 1 (getpropertyvalue e "Closed"))))
	(setq vrs (cond ((cdr (assoc 90 (entget e)))) (1))
	      pts (apply 'mapcar (cons '+ (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget e)))))
	      pnt (mapcar '/ pts (list vrs vrs))		 
	      oid (itoa (vla-get-objectid o))
	      fld (strcat "%<\\AcObjProp Object(%<\\_ObjId " oid ">%).Area \\f \"%lu2%pr1%ps[, m²]%ct8[1.0E-006]\">%"))
	(setq pnt (vlax-curve-getpointatdist e (/ (vlax-curve-getdistatparam e (vlax-curve-getendparam e)) 2))
	      oid (itoa (vla-get-objectid o))
	      fld (strcat "%<\\AcObjProp Object(%<\\_ObjId " oid ">%).Length \\f \"%lu2%pr1%ps[, m]%ct8[1.0E-003]\">%")))
      (setq txt (vla-addMText spc (setq pnt (vlax-3d-point pnt)) 0 fld))
      (vla-put-layer txt l)
      (vla-put-AttachmentPoint txt acAttachmentPointMiddleCenter)
      (vla-put-InsertionPoint txt pnt)
      ))
  (vla-endundomark doc)
  (princ)
  )

Apologies, that was very selfish of me.

 

I've attached the code which I've slightly amended with my very limited coding knowledge to round the figure to the nearest single decimal point.  Does anyone know of a was to get this to round UP to the nearest decimal point instead of just round?  I'm struggling with that one.

 

Thanks

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