prax3des Posted December 18, 2018 Share Posted December 18, 2018 Hi all, Could you help me with the following question? I try to insert a text in a line, polyline or circle whose value is the layer. In case of changing the value of the layer of my line, polyline or circle, this text could also change in value. helpme.dwg Quote Link to comment Share on other sites More sharing options...
CyberAngel Posted December 18, 2018 Share Posted December 18, 2018 To create a linetype with an interactive label, you'd need a piece of code that dynamically updates the acad.lin file and reloads the drawing whenever the name of an arbitrary layer changes. A simpler solution might be a command to draw wipeouts on the line and labels on top of the wipeouts. This is not as simple as it may sound. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 21, 2018 Share Posted December 21, 2018 So easy Mtext use a field OBJECT, Layer. CyberAngel "This is not as simple as it may sound". Yes it was that easy. Not sure were your going with the acad.lin idea. Quote Link to comment Share on other sites More sharing options...
prax3des Posted December 22, 2018 Author Share Posted December 22, 2018 With mtext and a field OBJECT if it would be worth it but it is not what I would really be interested. There is a Lisp (Laytext) that when selecting the lines and polyline inserts a text with layer value. It would be something similar but with the option that when changing the value of the layer the text was updated Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 23, 2018 Share Posted December 23, 2018 (edited) prax3des that's what a field does, the lisp would just do the steps in involved in creating the mtext. Make a mtext use a field then change the layer of the object, you must do a regen to see it change. When creating the mtext you change the string to be the field expression ;;-------------------=={layers 2 Field }==--------------------;; ;; ;; ;; Creates an MText Field referencing the layer ;; ;; of selected object. ;; ;;------------------------------------------------------------;; ;;Original code is Areas to field by ;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;; Area string changed to Layer By BIGAL DEC 2018 ;;------------------------------------------------------------;; (defun c:L2F nil (c:Layers2Field)) (defun c:Layers2Field ( / *error* _StartUndo _EndUndo acdoc acspc format pt Obj fld ) (vl-load-com) (defun *error* ( msg ) (if acdoc (_EndUndo acdoc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (defun _StartUndo ( doc ) (_EndUndo doc) (vla-StartUndoMark doc) ) (defun _EndUndo ( doc ) (if (= 8 (logand 8 (getvar 'UNDOCTL))) (vla-EndUndoMark doc) ) ) (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object)) acspc (vlax-get-property acdoc (if (= 1 (getvar 'CVPORT)) 'Paperspace 'Modelspace)) ) (while (setq obj (vlax-ename->vla-object (car (entsel)))) (setq pt (getpoint "\nPick Point for Field: ")) (setq fld (STRCAT "%<\\AcObjProp Object(%<\\_ObjId " (LM:GetObjectID ACdoc obj ) ">%).Layer \\f \"%tc1\">%")) (vla-addMText acspc (vlax-3D-point (trans pt 1 0)) 0. fld) ) (princ) ) ;;-------------------=={ Get ObjectID }==---------------------;; ;; ;; ;; Returns the ObjectID string for the supplied VLA-Object ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; doc - VLA Document Object (req'd for 64-bit systems) ;; ;; obj - VLA Object to query ;; ;;------------------------------------------------------------;; ;; Returns: ObjectID string for VLA-Object ;; ;;------------------------------------------------------------;; (defun LM:GetObjectID ( doc obj ) (if (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE")) (vlax-invoke-method (vla-get-Utility doc) 'GetObjectIdString obj :vlax-false) (itoa (vla-get-Objectid obj)) ) ) (princ) Edited December 23, 2018 by BIGAL Quote Link to comment Share on other sites More sharing options...
prax3des Posted December 26, 2018 Author Share Posted December 26, 2018 (edited) Hello Bigal, thank you very much for the Lisp, it's just almost what I'm looking for. Only that I would need to be able to choose multiple objects (line, polyline, ...) and that the point of selection was the midpoint. I usually use this lisp. My idea is to modify it so that changing the layer will update the text. Quote ;; LayText.lsp by Lee McDonnell, 03.12.2009 ;; Function will display layer information ;; at midpoint of every line selected. (defun c:LayText (/ *error* mk_txt DOC ENT I IPT LANG OFAC P SPC SS TOBJ TSZE UFLAG) (vl-load-com) (setq oFac 1) ;; Offset Factor (setq tSze nil) ;; Text Size ~ nil for TEXTSIZE Variable (defun *error* (msg) (and uFlag (vla-EndUndoMark doc)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ)) (defun mk_txt (p v) (vla-addText spc v (vlax-3D-point p) tSze)) (setq doc (vla-get-ActiveDocument (vlax-get-Acad-Object)) spc (if (zerop (vla-get-activespace doc)) (if (= (vla-get-mspace doc) :vlax-true) (vla-get-modelspace doc) (vla-get-paperspace doc)) (vla-get-modelspace doc))) (or tSze (setq tSze (getvar "TEXTSIZE"))) (if (setq i -1 ss (ssget '((0 . "*LINE,ARC,CIRCLE,ELLIPSE")))) (progn (setq uFlag (not (vla-StartUndoMark doc))) (while (setq ent (ssname ss (setq i (1+ i)))) (setq iPt (vlax-curve-getPointatDist ent (/ (- (vlax-curve-getDistatParam ent (vlax-curve-getEndParam ent)) (vlax-curve-getDistatParam ent (vlax-curve-getStartParam ent))) 2.))) (setq lAng (angle '(0 0 0) (vlax-curve-getFirstDeriv ent (vlax-curve-getParamatPoint ent iPt)))) (if (equal lAng (/ pi 2.) 0.001) (setq lAng (/ pi 2.))) (if (equal lAng (/ (* 3 pi) 2.) 0.001) (setq lAng (/ (* 3 pi) 2.))) (cond ( (and (> lAng (/ pi 2)) (<= lAng pi)) (setq lAng (- lAng pi))) ( (and (> lAng pi) (<= lAng (/ (* 3 pi) 2))) (setq lAng (+ lAng pi)))) (setq tObj (mk_txt (setq p (polar iPt (+ lAng (/ pi 2.)) (* oFac tSze))) (vla-get-Layer (vlax-ename->vla-object ent)))) (vla-put-Alignment tObj acAlignmentMiddleCenter) (vla-put-TextAlignmentPoint tObj (vlax-3D-point p)) (vla-put-Rotation tObj lAng)) (setq uFlag (vla-EndUndoMark doc)))) (princ)) Quote Edited December 26, 2018 by prax3des Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 27, 2018 Share Posted December 27, 2018 You just have to add the Fld and mtext lines in correct spot. Sometimes getting the field statement to work can be tricky. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.