TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: jvillarreal on October 04, 2010, 08:24:55 PM

Title: Elevation labeling
Post by: jvillarreal on October 04, 2010, 08:24:55 PM
Here are a couple more contour labeling routines to add to the site.

DyamicContourLabeler will allow 2 point selections and dynamically display the elevations of lines, arcs, polylines, and 3d polylines between the points.
(uses ssget->vla-list by CAB)

Label-Contours will allow user to create a polyline path and display elevations at intersection.
(uses ssget->vla-list by CAB and TracePline by Joe Burke)

Maybe someone can find them useful
Title: Re: Elevation labeling
Post by: zanze02 on October 05, 2010, 07:37:37 AM
good application, but
"AcDb2dPolyline" is to add.
Sorry for my bad english.
Title: Re: Elevation labeling
Post by: jvillarreal on October 05, 2010, 02:48:48 PM
Hi Zanze,
Glad you like it. I've updated the code to include 2dpolylines.
Title: Re: Elevation labeling
Post by: jvillarreal on October 06, 2010, 04:17:36 PM
If anyone is having trouble with DynamicContourLabeler erroring out, replace the get_interpts function with this:

Code: [Select]
(defun get_interpts (obj1 obj2)
(vlax-invoke obj1 'IntersectWith obj2 acExtendNone)
)


Thanks to Lee Mac for pointing this out in another topic (http://www.theswamp.org/index.php?topic=31737.msg372449#msg372449 (http://www.theswamp.org/index.php?topic=31737.msg372449#msg372449))
Title: Re: Elevation labeling
Post by: ziko30 on October 26, 2010, 10:24:34 AM
The dynamic labeler routine is very close to what I need to help me with a project. But I need for it to insert a block and give the block the same Z value as the contour line instead of inserting the value of the contour line itself. And if possible, to insert the block on every vertice of the contour line by selecting the line just once.

Usually I am able to  tweak a routine for my purposes or ask for suggestions and proceed from there.  But this routine looks a lot more involved ... would appreciate your help. 
Title: Re: Elevation labeling
Post by: jvillarreal on October 26, 2010, 12:34:24 PM
Code: [Select]
(defun c:ib (/ olderror ActDoc usermutt *Space* initialpt plst input sset templst param endparam obj objlist)
(vl-load-com)
(setq olderror *error*)
(defun *error* (msg)
(setvar 'NOMUTT usermutt)
    (if
      (not
        (member
          msg
          '("console break" "Function cancelled" "quit / exit abort" "")
        )
      )
       (princ (strcat "\nError: " msg))
    ) ; endif
    (setq *error* olderror)
    (vla-EndUndoMark ActDoc)
    (princ)
) ;end error function

;;ssget->vla-list by CAB

(defun ssget->vla-list (ss / i ename allobj)
       (setq i -1)
       (while (setq  ename (ssname ss (setq i (1+ i))))
         (setq allobj (cons (vlax-ename->vla-object ename) allobj))
       )
       allobj
)


(setq usermutt (getvar "NOMUTT"))
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vla-EndUndoMark ActDoc)
(vla-StartUndoMark ActDoc)
(setq *Space* (vlax-get-property ActDoc (nth (vla-get-ActiveSpace ActDoc)'("PaperSpace" "ModelSpace"))))
(setq sset (ssget (list (cons 0 "*POLY*"))))
(setvar "NOMUTT" 1)
(and sset
(setq linework (ssget->vla-list sset))
(foreach x linework
(and
       (setq typ (vlax-get x 'ObjectName))
       (member typ '("AcDb2dPolyline" "AcDbPolyline" "AcDbLWPolyline" "AcDb3dPolyline"))
  (setq param 0
           endparam (vlax-curve-getEndParam x)
       );setq
  (while (<= param endparam)
(setq obj
 (vla-insertblock *Space*
   (vlax-3d-point
     (vlax-curve-getPointAtParam x param)
   )
   "C:\\Prop Spot Elevation.dwg" 1.0 1.0 1.0 0.0
 )
)
(setq param (1+ param))
)
        )
)
);and
(setq *error* olderror)
(setvar 'NOMUTT usermutt)
(vla-EndUndoMark ActDoc)
(princ)
);defun

Just replace "C:\\Prop Spot Elevation.dwg" with your block
Title: Re: Elevation labeling
Post by: ziko30 on October 26, 2010, 01:45:47 PM
Great! ...that worked exactly the way I want to... Thanks and have a great day.
Title: Re: Elevation labeling
Post by: jvillarreal on October 26, 2010, 01:52:32 PM
No problem ziko. Glad it worked for you.
If you wanted to place the z value in the attribute of your proposed spot elevation you could replace the contents of while with this..
Code: [Select]
(setq elev (fix (caddr (setq pt (vlax-curve-getpointatparam x param)))))
(setq obj
  (vla-insertblock *Space*
    (vlax-3d-point
      pt
    )
    "Your Block path/name" 1.0 1.0 1.0 0.0
  )
)

(and
  (safearray-value
    (setq atts
      (vlax-variant-value
        (vla-getattributes obj)
      )
    )
  )
  (foreach tag (vlax-safearray->list atts)
    (vla-put-textstring tag (itoa elev))
   )
)

(setq param (1+ param))
Title: Re: Elevation labeling
Post by: ziko30 on October 26, 2010, 04:48:46 PM
I replaced the code in the while block and ran the routine. Looked like I got the same result as the first routine. But it's probably that I don't work that much with tagging blocks with attributes. The first routine you changed for me works and meets my requirements. I did what I thought would be a couple of days of work monotonous work in a half hour. But to move up a notch in skill, I will look at second routine again to see if I can tag my blocks with attributes.

This is how I set it up
Code: [Select]
(while (setq elev (fix (caddr (setq pt (vlax-curve-getpointatparam x param)))))
(setq obj
  (vla-insertblock *Space*
    (vlax-3d-point
      pt
    )
    "I:\\Projects\\Drainage Study October 2010\\Block.dwg" 1.0 1.0 1.0 0.0
  )
)

(and
  (safearray-value
    (setq atts
      (vlax-variant-value
        (vla-getattributes obj)
      )
    )
  )
  (foreach tag (vlax-safearray->list atts)
    (vla-put-textstring tag (itoa elev))
   )
)

(setq param (1+ param))
)