Page 1 of 2 12 LastLast
Results 1 to 10 of 16

Thread: Prefix/Suffix Lisp

  1. #1
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Prefix/Suffix Lisp

    Hi everyone,

    I need some help getting this code to work again and also to have it do a suffix as well.

    it is design to add a prefix before existing layers in a drawing.

    So if I have these existing layer names:

    walk
    drive, Etc...

    run lpfix and I get this after I enter l-

    l-walk
    l-drive, Etc...

    But for some reason I now getting

    Command: (LOAD "Z:/EDGCustomFiles/LPFIX.lsp")
    Type LPFIX to run.........
    Command: lpfix
    Enter Layer Prefix : d4
    ; error: bad argument type: stringp nil
    Code:
    (prompt "nType LPFIX to run.........")
    (defun C:LPFIX ( / acadDocument theLayers layName pre)
    (vl-load-com)
    (setq pre (getstring "nEnter Layer Prefix : "))
    (setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
    (setq theLayers (vla-get-layers acadDocument))
    (vlax-map-collection theLayers 'layer-mod)
    (princ)
    );defun
    (defun layer-mod (theLayer)
      (setq layName (vlax-get-property theLayer 'Name))
      (if (not (member layName '("0" "Defpoints" "MVIEW" "NONPRINT" "SCAN" "XREF" "XREF-REF")))
    	(vla-put-Name thelayer (strcat pre layName))
      ) ;if
    );defun
    (princ)
    I now also need code that will place a suffix at the end of the existing layers.

    l-walk
    l-drive, Etc...

    run LSUF and I get this after I enter 96

    l-walk96
    l-drive96, Etc...

    I took a shot at writing the code but its not running.

    Code:
    prompt "nType LSUF to run.........")
    (defun C:LSUF ( / acadDocument theLayers layName suf)
    (vl-load-com)
    (setq suf (getstring "nEnter Layer suffix : "))
    (setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
    (setq theLayers (vla-get-layers acadDocument))
    (vlax-map-collection theLayers 'layer-mod)
    (princ)
    );defun
    (defun layer-mod (theLayer)
      (setq layName (vlax-get-property theLayer 'Name))
      (if (not (member layName '("0" "Defpoints" "MVIEW" "NONPRINT" "SCAN" "XREF" "XREF-REF")))
    	(vla-put-Name thelayer (strcat layName suffix ))
      ) ;if
    );defun
    (princ)
    Therefore, I was hoping that someone could combined both lisps into one and have ask if you would like the text at the prefix or suffix.

    Thanks as always

    Kyle C.

  2. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,804
    Login to Give a bone
    0

    Default Re: Prefix/Suffix Lisp

    To find your error, open the code in the VLIDE, load it and run it. When you get the error, switch back to the VLIDE and choose "Error trace" from the View menu. This will give you a pretty good clue as to where it's bombing.

    The specific error you are receiving (bad argument type: stringp nil) is because something is expecting a string and it's receiving nil

    Here is a single file to do both.

    Code:
    (defun layer-mod (theLayer)
      (setq layName (vlax-get-property theLayer 'Name))
      (if (not (member layName
    		   '("0"	  "Defpoints"
    		     "MVIEW"	  "NONPRINT"
    		     "SCAN"	  "XREF"
    		     "XREF-REF"
    		    )
    	   )
          )
        (vla-put-Name thelayer (strcat pre layName suf))
      )
    )
    (defun C:LPFIX (/ acadDocument theLayers layName pre suf)
      (vl-load-com)
      (setq pre (getstring "\n Enter Layer Prefix: "))
      (setq suf (getstring "\n Enter Layer Suffix: "))
      (setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
      (setq theLayers (vla-get-layers acadDocument))
      (vlax-map-collection theLayers 'layer-mod)
      (princ)
      (vlax-release-object theLayers)
      (vlax-release-object acadDocument)
      (princ)
    )
    (prompt "\n Type LPFIX to run.........")
    (princ)
    R.K. McSwain | CAD Panacea |

  3. #3
    AUGI Addict .T.'s Avatar
    Join Date
    2000-12
    Location
    Lost
    Posts
    1,473
    Login to Give a bone
    0

    Default Re: Prefix/Suffix Lisp

    Hi Kyle,

    At first glance, you don't pass the variable pre to layer-mod and pre is declared local to c:lpfix, so pre is probably nil when layer-mod looks for it.

    Code:
    ;snip
    (defun layer-mod (theLayer)
      (setq layName (vlax-get-property theLayer 'Name))
      (if (not (member layName '("0" "Defpoints" "MVIEW" "NONPRINT" "SCAN" "XREF" "XREF-REF")))
    (vla-put-Name thelayer (strcat pre layName))
      ) ;if
    );defun
    ;snip

    I'll try and have a closer look at it a little later, I have a meeting...

    I hope this helps. Gotta run,

  4. #4
    AUGI Addict .T.'s Avatar
    Join Date
    2000-12
    Location
    Lost
    Posts
    1,473
    Login to Give a bone
    0

    Default Re: Prefix/Suffix Lisp

    Meeting canceled

    R.K., because the variables pre and suff are declared local to c:lpfix, don't pre and suff need to be passed to layer-mod? Or did I miss something?

    TIA

  5. #5
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Prefix/Suffix Lisp

    Quote Originally Posted by timcreary
    Meeting canceled

    R.K., because the variables pre and suff are declared local to c:lpfix, don't pre and suff need to be passed to layer-mod? Or did I miss something?

    TIA
    They don't have to be because Layer-Mod is being ran inside the main routine. It would be better coding practice to do it that way, but not necessary [IMHO].

  6. #6
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,804
    Login to Give a bone
    0

    Default Re: Prefix/Suffix Lisp

    "pre" won't be nil, unless the user doesn't enter a string at the prompt.

    Even though the argument isn't passed to the (layer-mod) function, it's global to the (lpfix) function at that point and therefore available to (layer-mod).

    If (layer-mod) isn't used outside of this lisp, then it could be defined within the (lpfix) defun.
    R.K. McSwain | CAD Panacea |

  7. #7
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Prefix/Suffix Lisp

    Quote Originally Posted by rkmcswain
    "pre" won't be nil, unless the user doesn't enter a string at the prompt.
    "pre" and "suf" will never be nil, if enter is pressed when prompted, then it just returns a null string [""]. FYI...

  8. #8
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Re: Prefix/Suffix Lisp

    rkmcswain,

    Thank you for the code & just want to give you a heads up (see comment in "red"). after I fix that problem it runs great.

    Quote Originally Posted by rkmcswain
    ...
    Code:
    (defun layer-mod (theLayer)
    (setq layName (vlax-get-property theLayer 'Name))
    (if (not (member layName
    		 '("0"	 "Defpoints" <-If Defpoints is not capitize it will add a suffix to it
    		 "MVIEW"	 "NONPRINT"
    		 "SCAN"	 "XREF"
    		 "XREF-REF"
    		 )
    	 )
    )
    (vla-put-Name thelayer (strcat pre layName suf))
    )
    )
    (defun C:LPFIX (/ acadDocument theLayers layName pre suf)
    (vl-load-com)
    (setq pre (getstring "n Enter Layer Prefix: "))
    (setq suf (getstring "n Enter Layer Suffix: "))
    (setq acadDocument (vla-get-activedocument (vlax-get-acad-object)))
    (setq theLayers (vla-get-layers acadDocument))
    (vlax-map-collection theLayers 'layer-mod)
    (princ)
    (vlax-release-object theLayers)
    (vlax-release-object acadDocument)
    (princ)
    )
    (prompt "n Type LPFIX to run.........")
    (princ)
    Kyle C.

  9. #9
    I could stop if I wanted to cadd4la's Avatar
    Join Date
    2001-12
    Location
    Newport Beach, CA
    Posts
    399
    Login to Give a bone
    0

    Default Re: Prefix/Suffix Lisp

    Tim,

    Thanks for your input.

    Kyle C.
    Quote Originally Posted by timcreary
    Hi Kyle,

    At first glance, you don't pass the variable pre to layer-mod and pre is declared local to c:lpfix, so pre is probably nil when layer-mod looks for it.

    Code:
    ;snip
    (defun layer-mod (theLayer)
    (setq layName (vlax-get-property theLayer 'Name))
    (if (not (member layName '("0" "Defpoints" "MVIEW" "NONPRINT" "SCAN" "XREF" "XREF-REF")))
    (vla-put-Name thelayer (strcat pre layName))
    ) ;if
    );defun
    ;snip
    ...

  10. #10
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,804
    Login to Give a bone
    0

    Default Re: Prefix/Suffix Lisp

    Quote Originally Posted by CiphDRMRS
    "pre" and "suf" will never be nil, if enter is pressed when prompted, then it just returns a null string [""]. FYI...
    Correct. My bad.
    R.K. McSwain | CAD Panacea |

Page 1 of 2 12 LastLast

Similar Threads

  1. Dim Prefix Suffix
    By U.Rackharrow in forum AutoLISP
    Replies: 2
    Last Post: 2009-05-01, 03:47 PM
  2. Dimension prefix and suffix
    By clog boy in forum Revit Architecture - General
    Replies: 2
    Last Post: 2007-04-19, 01:01 PM
  3. Prefix / Suffix for Attributes
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2007-03-02, 06:09 PM
  4. Add a Prefix/Suffix to Text
    By ReachAndre in forum AutoLISP
    Replies: 3
    Last Post: 2006-12-26, 08:14 PM
  5. 8.1/E - Dim Prefix and Suffix on Options Bar
    By janunson in forum Revit Architecture - Wish List
    Replies: 0
    Last Post: 2006-02-01, 07:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •