Jump to content
prax3des

Text value the layer in line, polyline

Recommended Posts

prax3des

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

Share this post


Link to post
Share on other sites
CyberAngel

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.

Share this post


Link to post
Share on other sites
BIGAL

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.

Share this post


Link to post
Share on other sites
prax3des

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

Share this post


Link to post
Share on other sites
BIGAL

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 by BIGAL

Share this post


Link to post
Share on other sites
prax3des

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 by prax3des

Share this post


Link to post
Share on other sites
BIGAL

You just have to add the Fld and mtext lines in correct spot. Sometimes getting the field statement to work can be tricky.

Share this post


Link to post
Share on other sites

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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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