Rovinator Posted January 13 Posted January 13 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 January 13 Posted January 13 Can you upload a sample drawing with just a few blocks in it? Quote
pkenewell Posted January 13 Posted January 13 (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 January 13 by pkenewell Quote
Rovinator Posted January 14 Author Posted January 14 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 January 14 Posted January 14 (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 January 14 by pkenewell Forgot to localize some variables. 1 Quote
Rovinator Posted January 15 Author Posted January 15 @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 January 15 Posted January 15 (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 January 15 by pkenewell Added additional checks into the command for Block and eliminated command echos, adding a rotation prompt. Quote
Rovinator Posted January 15 Author Posted January 15 @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 January 16 Posted January 16 @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 January 17 Author Posted January 17 @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 January 17 Posted January 17 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
Rovinator Posted January 18 Author Posted January 18 @pkenewell I hope this helps, the Tag is setup like this: and the setup in Plant 3D is like this I am trying to use the property in Bold below: ; Property values: ; Application (RO) = #<VLA-OBJECT IAcadApplication 00007ff683bc40f0> ; Document (RO) = #<VLA-OBJECT IAcadDocument 00000148b4b7f678> ; Tag (RO) = "HV-223\\pV205-80?" Quote
pkenewell Posted January 20 Posted January 20 @Rovinator OK Thanks, do you need you change the "\p" delimiter to something else? Seems you added the "\p" in the first place to try to create a line break and eliminate the "-". The program updated below can work with the "\p" if you want to leave it in. However, if you change the delimiter back to "-", since there are more "-" characters used in the string and tag format, it will cause the program to change the number of parts to split. It would be better to use a unique character that is not used anywhere else in the tag string. You could use something like a colon ":", or an underscore "_". NOTE: If you go back to the dash "-" character, then my last version of the program will work, except for leaving behind the "-" at the end of the first line (I can fix that - if that is the case). ALSO NOTE: I will not be able to test the code properly, because without a full project, I cannot go into the "Tag Format Setup". I don't use or know Plant 3D very well even though I have a copy in my Autodesk collection. I don't know how I would setup a project to test it without doing a full crash course on using plant 3D. This update to the program (below) will split the tag at the current "\p" delimiter. If you choose to change to a different unique delimiter character, you can change it in the commented area of the program, under the comment "Tag Delimiter Character". REMEMBER- it must be a UNIQUE delimiter that is not used in any other part of the string (it also must be different to other delimiters in the tag format). (defun c:VTL ( / cnsap delimiter myEnt oecho pt1 rot sc strlst valvetag vlaobj) ;; ========= Tag Delimiter Character ========== ;; Change this to any unique character string to split the ;; Plant 3D tag into 2 lines. (setq delimiter "\\p") ;; =========================================== (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: <10.0>") sc (if sc sc 10.0) ) (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 delimiter))) 1) ) (progn (setq valvetag (strcat (nth 0 strlst) "\\P" (nth 1 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) Quote
Rovinator Posted January 20 Author Posted January 20 @pkenewell, This works like a dream!!! My nightmares are over Thank you for all you time, effort and patience. I owe you a good few beers!! I assume you are not from South Africa, there seems to be a time difference in our communication, otherwise I would buy you one in person. If you ever need any assistance with Plant 3D, please do not hesitate to contact me, I would be more than willing to try to assist, no guarantees though Thanks again for the help!!! 1 Quote
pkenewell Posted January 20 Posted January 20 @Rovinator Your very welcome! Ya if I were local I'd take you up on your offer, but alas I'm in Michigan USA (it's COLD here right now LOL). Quote
Rovinator Posted January 21 Author Posted January 21 @pkenewell My sisters live in USA, one in LA and one in Florida, my niece is at University of Michigan, so I am a Wolverines supporter!! I could get her to courier some beers Thanks again for the help!! Quote
BIGAL Posted January 21 Posted January 21 (edited) @pkenewell its going to be 38c tomorrow, here in AUS, so going down the beach. Mind you they say thunderstorms will hits us in the afternoon. So we may get flooding, we are in our fire season I have bushland near my home so keep watch of what is going on. After California fires pointed out you have to be prepared. Edited January 21 by BIGAL 1 Quote
pkenewell Posted January 21 Posted January 21 (edited) 8 hours ago, Rovinator said: @pkenewell My sisters live in USA, one in LA and one in Florida, my niece is at University of Michigan, so I am a Wolverines supporter!! I could get her to courier some beers Thanks again for the help!! @Rovinator HaHa! I work literally only a few Km away from UofM campus! That's OK though - no beer necessary! Edited January 21 by pkenewell Quote
pkenewell Posted January 21 Posted January 21 5 hours ago, BIGAL said: @pkenewell its going to be 38c tomorrow, here in AUS, so going down the beach. Mind you they say thunderstorms will hits us in the afternoon. So we may get flooding, we are in our fire season I have bushland near my home so keep watch of what is going on. After California fires pointed out you have to be prepared. @BIGAL So true - be prepared! I wish you the best for your summer out there. I wonder if you might recognise my last name (Kenewell)? I have ALLOT of relatives that live in AUS that I keep in contact with via FB. I'd love to visit someday (when I'm a bit more wealthy LOL)! 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.