Contour Labeling LISP help PLEASE :)

Contour Labeling LISP help PLEASE :)

KMaloneyPCKDF
Community Visitor Community Visitor
901 Views
6 Replies
Message 1 of 7

Contour Labeling LISP help PLEASE :)

KMaloneyPCKDF
Community Visitor
Community Visitor

Hey everyone!

 

For some reason, a lisp routine is no longer working for me (see attached).  This lisp would automate the labeling of contour lines, but for some reason, I'm now getting an error message that says, "Item selected is not a curve object!".  It never used to give me that error. 

 

Any thoughts on how this could be fixed?  I'm not very good with coding, so I would be very grateful if someone could help revise the lisp! Please let me know if I can provide any more info.

 

All the best, 

 

Kellen

 

 

0 Likes
902 Views
6 Replies
Replies (6)
Message 2 of 7

hak_vz
Advisor
Advisor

Lisp is working just fine with contours created as polylines. Attach sample drawing so that we can try to resolve what causes problem at your side.

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 3 of 7

calderg1000
Mentor
Mentor

Regards @KMaloneyPCKDF 
I went through the routine and tested it with various types of entities, checking that it works fine.
You may be selecting an entity that does not adequately represent a contour line.

To recognize what type of selection you are making, after selecting the entity, check the properties box to see what type of object you are selecting.


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 4 of 7

Sea-Haven
Mentor
Mentor

Not all Polylines are the same there is at least 3 different types of plines. Polyline, 3dpolyline, LWpolyline older plines are different than current version plines. Some external software creates plines in odd ways I had just that problem recently, the (100 . "Acdb... it was different than a normal pline, so had to test for it.

 

(0 . "POLYLINE") (100 . "AcDb3dPolyline")

 

(0 . "LWPOLYLINE") (100 . "AcDbPolyline")

0 Likes
Message 5 of 7

hak_vz
Advisor
Advisor

@KMaloneyPCKDF  As others have stated, there ate different kinds of polylines, although IMO lwpolyline is best options. Here you have two functions that I regularly use at my work. One is for contour labeling, and other for setting elevations when received contours are flattened. In contours labeling function two options are commented

(; ) at beginning of the line, one is to put mask behind the elevation text, and other to trim contour so you can use what's needed in particular situation.

 

(defun c:lel ( / intersections textmask doc decplaces th e eo pt elev co ispts ang )
;Label lwpolyline contour at pick point and rotate answer to question is different from ""
(defun intersections ( ob1 ob2 mod / lst rtn )
    (if (and (vlax-method-applicable-p ob1 'intersectwith)
             (vlax-method-applicable-p ob2 'intersectwith)
             (setq lst (vlax-invoke ob1 'intersectwith ob2 mod))
        )
        (repeat (/ (length lst) 3)
            (setq rtn (cons (list (car lst) (cadr lst) (caddr lst)) rtn)
                  lst (cdddr lst)
            )
        )
    )
    (reverse rtn)
)
(setq doc (vla-get-activedocument (vlax-get-acad-object)) mspace (vla-get-modelspace doc))
(setq decplaces (getint "\nNumber of decimal places >"))
(setq th (getreal "\nText height"))
(while (setq e (entsel "\nPick point at contour > "))
(setq pt (cadr e) e (car e) eo (vlax-ename->vla-object e) pt (vlax-curve-getClosestPointTo eo pt))
(setq elev (rtos(vlax-get eo 'Elevation) 2 decplaces))
(setq co(vla-addcircle mspace (vlax-3d-point pt) 2))
(setq ispts (intersections eo co acextendnone))
(vla-delete co)
(setq ang (angle (car ispts) (cadr ispts)))
(if (> ang (/ pi 2)) (setq ang (- ang pi)))
(setq to (vla-AddText mspace elev (vlax-3d-point pt) th)) 
(vla-put-Alignment to acAlignmentMiddle)
(vla-put-TextAlignmentPoint to (vlax-3d-point pt))
(vla-put-Rotation to ang)
;(acet-textmask-make-wipeout (vlax-vla-object->ename to) 0.5)
(setq ro (strcase (getstring  "\nRotate >")))
(if (= (strlen ro ) 1) (command "_.rotate" (vlax-vla-object->ename to) "" pt 180))
(setvar 'cmdecho 0)
;(command "_.trim" (vlax-vla-object->ename to) "" (list (vlax-vla-object->ename eo) pt) "")
(setvar 'cmdecho 1)
)
(princ)
)

(defun c:repelev ( / *error* n pt1 base step e text pt2) 
	(defun *error* ()
		(setvar "cmdecho" 1)
		(princ)
	)	
	(setq base (getreal"\n New starting elevation: >")
		  step (getreal "\n Isohypse step (+ or - value) >:")
	)
	(setvar "cmdecho" 0)
	(princ (strcat "\nSelect isohypse(s) at " (rtos base 2 1) " Press 'Enter' when done): >"))
	(while (and (setq ss (ssget)) (> (sslength ss) 0))

				(setq i -1)
				(while (< (setq i (1+ i)) (sslength ss))
					(setq eo (vlax-ename->vla-object (ssname ss i)))
					(vlax-put eo 'Elevation base)
					(vlax-put eo 'Color 40)
				)
				(setq base (+ base step))
				(princ (strcat "\nSelect isohypse(s) at " (rtos base 2 1) " Press 'Enter' when done): >"))
			
		
	)
	(setvar "cmdecho" 1)
	(princ)
)

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 6 of 7

vladimir_michl
Advisor
Advisor
0 Likes
Message 7 of 7

john.uhden
Mentor
Mentor

I think what I wrote for myself works really well, if you want it.  It labels both heavy and light polylines as well as Land Desktop AECC_CONTOURs.

It masks the contour so there's there's no need to break it and it adjusts for twisted views to maintain readability.

You would have to add very little to make sure your text style and height are to your liking.

BUT, you should post a sample of your troublesome drawing so we can figure out why your code isn't working.

John F. Uhden

0 Likes