Jump to content

Recommended Posts

Posted

Hi all, I have a multiple line block to label objects the variable is something like this "HV-001\\pV500-100" or sometimes "HV-001\pV500-100" (single \) I was hoping the \p would populate the block attribute with the V500-100 on the second line but it doesn't 😞 what would the correct function be to replace the \p or \\p with either a space or just remove it with no space at all.

Thanks a lot.

Posted

Can you upload a sample drawing with just a few blocks in it?

Posted (edited)
8 hours ago, Rovinator said:

Hi all, I have a multiple line block to label objects the variable is something like this "HV-001\\pV500-100" or sometimes "HV-001\pV500-100" (single \) I was hoping the \p would populate the block attribute with the V500-100 on the second line but it doesn't 😞 what would the correct function be to replace the \p or \\p with either a space or just remove it with no space at all.

Thanks a lot.

 

@Rovinator As fuccaro said, please provide a sample drawing. Are you writing AutoLISP code? can you share a snippet of what / where the issue is?

 

I can note a few things.

 

1) the Attribute has to be a Multi-line Attribute, not a single line version.

2) The "\P" is the paragraph return code in the Multiline text. You can't use "\P" in the internal AutoCAD editor as it will add the extra escape character, taking it literally.

In an AutoLISP routine, when you supply a string you have to add the escape character - the extra backslash "\\P" - to prevent the AutoLISP interpreter from thinking it is a unicode character (like "\n").

 

Here is a reference to all the special formatting codes.

AutoCAD 2025 Help | Format Codes for Alternate Text Editor Reference | Autodesk
https://help.autodesk.com/view/ACD/2025/ENU/?guid=GUID-7D8BB40F-5C4E-4AE5-BD75-9ED7112E5967

 

Edited by pkenewell
Posted

Hi Guys, Thanks for the prompt reply, so here is a bit more information:

I am trying to tag a Plant 3D Valve in the model, so that the numbers are visible in Navisworks (a client request)

I have tried to write a lisp code and was hoping not to have to expose my limited knowledge of Autolisp 😄 Nevertheless, attached is the plant 3d Drawing with the tagged Valve, my block with multiline attribute and my crude Autolisp code, that I have cut and pasted from a number of other posts I have found.

Attachments:

Test Drawing.dwg - Plant 3D Sample Drawing

ValveNumberTag1.dwg - Block with Multiline Attribute

ValveTag.lsp - Autolisp Code.

Thanks a lot.

 

Test Drawing.dwg ValveTag.lsp ValveNumberTag1.dwg

Posted (edited)
14 hours ago, Rovinator said:

Test Drawing.dwg - Plant 3D Sample Drawing

ValveNumberTag1.dwg - Block with Multiline Attribute

ValveTag.lsp - Autolisp Code.

Thanks a lot.

@Rovinator Your code works, except you would have to either:

   1) Parse the "tag" property to add in the return code before inserting the tag.

   2) Add the return into the tag itself.

 

Here is some code for option 1. I added in the function (pjk-StrParse), and added in some basic error handling. Tested minimally. NOTE: this only works properly if your tags always have the SAME format, i.e. the same number of "-" dashes, such as X-X-X-X (the X"s can be any length)

(defun c:VTL ( / cnsap myEnt pt1 sc strlst valvetag vlaobj)
   (vl-load-com)
   ; get the Valve number from piping obj
   (setq CSNAP (getvar "osmode"))
   (setvar "osmode" 512)
   (if
      (and
         (setq SC    (getreal "\Text Height: "))
         (setq myEnt (car (entsel "\nSelect Valve: ")))
         (setq PT1   (getpoint "\Pick Label Location: "))
      )
      (progn
         (setq vlaobj (vlax-ename->vla-object myEnt))
         (if (vlax-property-available-p vlaobj 'Tag)
            (progn
               (setq ValveTag (vlax-get-property vlaobj 'Tag)
                     strlst   (pjk-Strparse valvetag "-")
                     valvetag (strcat (nth 0 strlst) "-" (nth 1 strlst) "-\\P" (nth 2 strlst) "-" (nth 3 strlst))
               )
               (setvar "ATTDIA" 0)
               (Command "-insert" "ValveNumberTag1" PT1 SC "" pause ValveTag "")
            )
            (princ "\nTag Property not found for select object.")
         )
      )
   )
   (setvar "osmode" CSNAP)
   (princ)
)

;|==============================================================================
  Function Name: (pjk-StrParse)
  Arguments:
     str = String; String to process
     del = String; Delimiter to separate the string
  Usage: (pjk-StrParse <string> <delimter>)
  Returns: List; A list of strings
  Description:
     Separates a string into a list of strings using a
     specified delimiter string; uses recursion.
================================================================================|;
(defun pjk-StrParse (str del / pos)
  (if (and str del)
     (if (setq pos (vl-string-search del str))
       (cons (substr str 1 pos) (pjk-StrParse (substr str (+ pos 1 (strlen del))) del))
       (list str)
     )
  )
) ;; End Function (pjk-StrParse)

 

Option 2 - NO CODE:

image.png.6e3e0cc37df4ce026307d1ffd71efeb5.png

Edited by pkenewell
Forgot to localize some variables.
  • Like 1
Posted

@pkenewell Thanks a lot for your assistance, I am getting the below error message when I run the Lisp, obviously I am doing something wrong or perhaps this is an indication of how little I really know 😄 

Select Valve: Pick Label Location: ; error: bad argument type: stringp nil.

 

Posted (edited)
9 hours ago, Rovinator said:

Select Valve: Pick Label Location: ; error: bad argument type: stringp nil.

@Rovinator I works fine for me so it's difficult to diagnose the problem unless you send a sample drawing with at least the part you were trying to tag. My guess is that you haven't assigned a tag to the part yet?

 

OK - try this. I added some additional error handling:

(defun c:VTL ( / cnsap myEnt oecho pt1 rot sc strlst valvetag vlaobj)
   (vl-load-com)
   ; get the Valve number from piping obj
   (setq cnsap (getvar "osmode")
         oecho (getvar "cmdecho")
   )
   (setvar "osmode" 512)
   (setvar "cmdecho" 0)
   (if
      (and
         (setq SC    (getreal "\nText Height: "))
         (setq myEnt (car (entsel "\nSelect Valve: ")))
         (tblsearch "BLOCK" "ValveNumberTag1")
      )
      (progn
         (setq vlaobj (vlax-ename->vla-object myEnt))
         (if (vlax-property-available-p vlaobj 'Tag)
            (if 
               (and
                  (setq ValveTag (vlax-get-property vlaobj 'Tag))
                  (> (length (setq strlst (pjk-Strparse valvetag "-"))) 3)
               ) 
               (progn
                  (setq valvetag (strcat (nth 0 strlst) "-" (nth 1 strlst) "-\\P" (nth 2 strlst) "-" (nth 3 strlst)))
                  (setvar "ATTDIA" 0)
                  (if
                     (and
                        (setq pt1 (getpoint "\nPick Label Location: "))
                        (setq rot (getangle pt1 "\nRotation angle: <0> ")
                              rot (if rot rot 0.0)
                        )
                     )
                     (Command "-insert" "ValveNumberTag1" pt1 SC "" (* (/ rot pi) 180.0) ValveTag "")
                  )
               )
               (princ "\nTag Property not assigned or in incorrect format. ")
            )
            (princ "\nTag Property not found for select object.")
         )
      )
      (if (not (tblsearch "BLOCK" "ValveNumberTag1"))(princ "\nBlock Name \"ValveNumberTag1\" not found."))
   )
   (setvar "osmode" cnsap)
   (setvar "cmdecho" oecho)
   (princ)
)

;|==============================================================================
  Function Name: (pjk-StrParse)
  Arguments:
     str = String; String to process
     del = String; Delimiter to separate the string
  Usage: (pjk-StrParse <string> <delimter>)
  Returns: List; A list of strings
  Description:
     Separates a string into a list of strings using a
     specified delimiter string; uses recursion.
================================================================================|;
(defun pjk-StrParse (str del / pos)
  (if (and str del)
     (if (setq pos (vl-string-search del str))
       (cons (substr str 1 pos) (pjk-StrParse (substr str (+ pos 1 (strlen del))) del))
       (list str)
     )
  )
) ;; End Function (pjk-StrParse)

 

Edited by pkenewell
Added additional checks into the command for Block and eliminated command echos, adding a rotation prompt.
Posted

@Rovinator It looks like your TAG is not properly formatted for my new code. Let me know if this is what it is the tag is supposed to be because I don't know Plant 3D very well. I re-assigned the tag and everything works for me. NOTE- my program adds the return code (\P) into the block attribute.

image.thumb.png.8a85144f94b8064db2733c59353cdb9f.png

Posted

@pkenewell The tag should be as you have it except for the dash after the 223 like below:

image.png.cbd94cf36113aea7aa35ad09b197eddc.png

Thanks again for all your help!!! Have a great weekend!!

Posted
8 hours ago, Rovinator said:

 The tag should be as you have it except for the dash after the 223 like below:

@Rovinator Ok - Is the entire sequence added to the "Code" part of the tag? Because when I re-enter the tag, it adds an extra dash in automatically. Please explain the tag format and how the tag is entered, because even if I add the tag all to the "Code" portion, it adds a "-?" on the end (see screenshot). Also - now there is no delimiter to separate the tag, except for maybe the "V"? Is it always the same?

image.png.403e7de0c6c215015f7d7fccc35e889e.png

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