See the top rated post in this thread. Click here

Results 1 to 6 of 6

Thread: Nil result and incrementing new layer names

  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 Nil result and incrementing new layer names

    Hi everyone,

    I'm looking to get some input about why I get nil when I load this program into AutoCAD, but the code works.

    Code:
    (defun c:delta ()
      (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
      (setq layers (vla-get-Layers doc))
    
      ; Change the color of existing layers
      (setq target-layers '("L-ANNO_REVC-A001" "L-ANNO_REVS-A001"))
      (foreach layer-name target-layers
        (setq layer (vla-Item layers layer-name))
        (if layer
          (vla-put-Color layer 246)
        )
      )
    
      ; Create a new layer L-ANNO_REVC-A002
      (create-new-layer doc "L-ANNO_REVC-A002" 5 "Continuous" "Annotation: Revision clouds Delta2")
    
      ; Create a new layer L-ANNO_REVS-A002
      (create-new-layer doc "L-ANNO_REVS-A002" 13 "Continuous" "Annotation: Revisions Delta2")
    )
    
    (defun create-new-layer (doc layer-name color linetype description)
      (setq layers (vla-get-Layers doc))
      (setq layer (vla-Add layers layer-name))
      (vla-put-Color layer color)
      (vla-put-Linetype layer linetype)
      (vla-put-Description layer description)
    )
    
    ; Run the main function
    (c:delta)
    I'm also looking to see if someone can take the code to the next level by having it add the two new layers but increase the layer name and layer description by 1. So if the file already has layers named "L-ANNO_REVC-A001", "L-ANNO_REVC-A002" and "L-ANNO_REVS-A001", "L-ANNO_REVS-A002" it will automatically go to "L-ANNO_REVC-A003" and "L-ANNO_REVS-A003", if it only has "L-ANNO_REVC-A001" and "L-ANNO_REVS-A001" it will create "L-ANNO_REVC-A002" and "L-ANNO_REVS-A002" and so on.

    Thanks,

    Cadd4la

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,057
    Login to Give a bone
    2

    Default Re: Nil result and incrementing new layer names

    Typically, the nil result is the last returned value in your code. You can suppress it by adding a princ as the last function of your routine.

    This will return the current highest revision level as determined by your layer name pattern. The number 14 is hard-coded to match your current pattern. This number is where your pattern appears to be numbers.
    Code:
    (defun _getRevisionLevel (doc pattern / rev rev-level rev-layer)
      (vlax-for layer (vla-get-layers doc)
        (if (wcmatch (strcase (setq rev-layer (vla-get-name layer)))
                     (strcase pattern)
            )
          (progn
            (if (and (not (vl-catch-all-error-p
                            (setq rev (vl-catch-all-apply
                                        'atoi
                                        (list (substr rev-layer 14))
                                      )
                            )
                          )
                     )
                     (> rev rev-level)
                )
              (setq rev-level rev)
            )
          )
        )
      )
      rev-level
    )
    This will take an integer and the desired string length and return the integer as a string with prefixed "0"s. It will return nil if the integer supplied is not able to be converted to string.

    Code:
    (defun _createRevisionString (level level-length)
      (if (not (vl-catch-all-error-p
                 (setq level (vl-catch-all-apply 'itoa (list level)))
               )
          )
        (while (< (strlen level) level-length)
          (setq level (strcat "0" level))
        )
        (setq level nil)
      )
      level
    )
    Taking these two sub-routines, you may be able to piece together the updates to your routine.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    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: Nil result and incrementing new layer names

    Opie,

    Thank you for your help, I will look into how these two codes can be incorporated into my code.

    Regards,

    Cadd4la

  4. #4
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    540
    Login to Give a bone
    0

    Default Re: Nil result and incrementing new layer names

    Opie (strlen str)

    (strlen "L-ANNO_REVC-A002") = 16

  5. #5
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,057
    Login to Give a bone
    0

    Default Re: Nil result and incrementing new layer names

    Quote Originally Posted by BIG-AL View Post
    Opie (strlen str)

    (strlen "L-ANNO_REVC-A002") = 16
    And where do the numbers appear to start in that "string"? The request was to increment the number by 1 for each additional layer with that prefix.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  6. #6
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    540
    Login to Give a bone
    0

    Default Re: Nil result and incrementing new layer names

    In your code you used 14 as the string search point so if the string is a different number of characters you can still look at the last 2 ie strlen - 2.

Similar Threads

  1. Incrementing text of format P1/L1/D1
    By peter in forum AutoLISP
    Replies: 5
    Last Post: 2018-06-08, 09:34 PM
  2. Replies: 8
    Last Post: 2016-05-18, 09:11 AM
  3. Incrementing an Integer parameter question
    By abecker.260769 in forum Revit Architecture - Families
    Replies: 6
    Last Post: 2010-09-01, 01:06 AM
  4. Auto Incrementing Grid Bubbles
    By JDRBWA in forum AutoLISP
    Replies: 0
    Last Post: 2008-05-02, 05:28 PM
  5. Change Layer names to other Layer names via a script?
    By tburke in forum AutoCAD Customization
    Replies: 5
    Last Post: 2006-12-04, 07:30 PM

Tags for this Thread

Posting Permissions

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