Rovinator Posted Monday at 08:02 AM Posted Monday at 08:02 AM 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. Quote
fuccaro Posted Monday at 12:57 PM Posted Monday at 12:57 PM Can you upload a sample drawing with just a few blocks in it? Quote
pkenewell Posted Monday at 04:43 PM Posted Monday at 04:43 PM (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 Monday at 04:50 PM by pkenewell Quote
Rovinator Posted Tuesday at 05:26 AM Author Posted Tuesday at 05:26 AM 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 Quote
pkenewell Posted Tuesday at 02:56 PM Posted Tuesday at 02:56 PM (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: Edited Tuesday at 08:10 PM by pkenewell Forgot to localize some variables. 1 Quote
Rovinator Posted Wednesday at 05:15 AM Author Posted Wednesday at 05:15 AM @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.  Quote
pkenewell Posted Wednesday at 02:09 PM Posted Wednesday at 02:09 PM (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 Wednesday at 02:57 PM by pkenewell Added additional checks into the command for Block and eliminated command echos, adding a rotation prompt. Quote
Rovinator Posted Wednesday at 04:29 PM Author Posted Wednesday at 04:29 PM @pkenewell Please find test drawing and Tag block attached. Thanks a lot for you help and patience!! ValveNumberTag1.dwg Test Drawing.dwg Quote
pkenewell Posted Thursday at 02:41 PM Posted Thursday at 02:41 PM @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. Quote
Rovinator Posted 20 hours ago Author Posted 20 hours ago @pkenewell The tag should be as you have it except for the dash after the 223 like below: Thanks again for all your help!!! Have a great weekend!! Quote
pkenewell Posted 11 hours ago Posted 11 hours ago 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? Quote
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.