Lsp continu when file not have attributes

Lsp continu when file not have attributes

DGRL
Advisor Advisor
913 Views
7 Replies
Message 1 of 8

Lsp continu when file not have attributes

DGRL
Advisor
Advisor

Dear forum members,

 

I have a routine that read out folders and subfolders and makes a list of all the dwg's in those folder

I also work with exclusion the following way

 

(vl-remove "." (vl-remove ".." (vl-remove "RECENT" (vl-remove "BACKUP" (vl-remove "QuickIsos" (vl-remove "Live Preview" (vl-remove "Check_A1" (vl-remove "VOID" (vl-directory-files folder nil -1)))))))))
  

The code above will exclude all the folders listed and that's good

I also use a code that filters out files

 

(setq ORTHO (vl-remove (strcat ORTHOS1 "Orthographic View Selection 1.dwg") ORTHO))

 

Does anybody knows how to modify this piece of code in such a way that the lsp will just continu if there are no attributes inside the current dwg?|
Because now the routine will stop working when opening an dwg that does not contain any attributes.

 

Thanks in advance

Best regards,

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
914 Views
7 Replies
Replies (7)
Message 2 of 8

roland.r71
Collaborator
Collaborator

Could you post the routine?

As the above code doesn't seem to have any relation to attributes being present or not ...

0 Likes
Message 3 of 8

DGRL
Advisor
Advisor

The only relation in my code with the attributes is this

 

(defun LM:getattributevalue ( blk tag / val enx )
    (while
        (and
            (null val)
            (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk)))))))
        )
        (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
            (setq val (cdr (assoc 1 enx)))
        )
    )
)

(setq blk (ssname (ssget "x" (list (cons 0 "INSERT") (cons 2 "Title Block")))0))
(setq revdate (LM:GetAttributeValue blk "Rev_Date" ))

 

 

To get a list of all the files in a folder I use Lee Mac his routine GetAllFiles

 

 

(defun GetAllFiles ( Dir Subs Filetype / _GetSubFolders )
 
  (defun _GetSubFolders ( folder )
    (apply 'append
      (mapcar
        (function
          (lambda ( f )
            (cons (setq f (strcat folder "\\" f)) (_GetSubFolders f))
          )
        )
        (vl-remove "." (vl-remove ".." (vl-remove "RECENT" (vl-remove "BACKUP" (vl-remove "QuickIsos" (vl-remove "Live Preview" (vl-remove "Check_A1" (vl-remove "VOID" (vl-directory-files folder nil -1)))))))))
      )
    )
  )

  (apply 'append
    (mapcar
      (function
        (lambda ( Filepath )
          (mapcar
            (function
              (lambda ( Filename ) (strcat Filepath "\\" Filename))
            )
            (vl-directory-files Filepath Filetype 1)
          )
        )
      )
      (cons Dir (if subs (_GetSubFolders Dir)))
    )
  )
)

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 4 of 8

roland.r71
Collaborator
Collaborator

@DGRL wrote:

The only relation in my code with the attributes is this

 

(defun LM:getattributevalue ( blk tag / val enx )
    (while
        (and
            (null val)
            (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk)))))))
        )
        (if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
            (setq val (cdr (assoc 1 enx)))
        )
    )
)

(setq blk (ssname (ssget "x" (list (cons 0 "INSERT") (cons 2 "Title Block")))0))
(if blk (setq revdate (LM:GetAttributeValue blk "Rev_Date" )))

  


Here you need to check if there IS a selection set, or Lee Mac's function fails (error: bad argument type: lselsetp nil)

Message 5 of 8

DGRL
Advisor
Advisor

Dear @roland.r71

 

That is a good 1 though I was thinking of making an continu on error

 

(setq blk (ssname (ssget "x" (list (cons 0 "INSERT") (cons 2 "Title Block")))

(if blk ( do some code ))

(if not blk ( resume next in list ))

 

Is this possible?

 

Thanks for your effort 🙂

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 6 of 8

DGRL
Advisor
Advisor

Dear @roland.r71

 

If I use your method and the block is not present it will give error;   error: bad argument type: lselsetp nil

Isnt it better to do it like

If block is present do this and when block is not present resume next

 

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 7 of 8

roland.r71
Collaborator
Collaborator

@DGRL wrote:

Dear @roland.r71

 

That is a good 1 though I was thinking of making an continu on error

 

(setq blk (ssname (ssget "x" (list (cons 0 "INSERT") (cons 2 "Title Block")))

(if blk ( do some code ))

(if not blk ( resume next in list ))

 

Is this possible?

 

Thanks for your effort 🙂


Yes, even easier, the if statement comes with an else.

It actually accepts 2 "functions". The first if True, second if not.

 

(if blk

   (princ "BLK has a value")

   (princ "BLK has no value")

)

 

More lines of code?

That's where the (progn is for, to keep all code together as 1, for the if to execute the right part.

(if blk

   (progn

      (princ "BLK has ")

      (princ "a value")

   )

; else

   (progn

      (princ "BLK has ")

      (princ "no value")

   )

)

 

... but what "next in list" do you mean? what list?

0 Likes
Message 8 of 8

roland.r71
Collaborator
Collaborator

The error must be coming from elsewhere. The

(if blk

 

is there to prevent calling the LM function without a valid selection set (& THAT would return the error that the selection set is nil (lselsetp nil))

 

For anything you do after retrieving the 'revdate', keep in mind:

 

revdate can be nil, if there is no title block. (& the selection set is nil too, in such case)

So you might want to skip the rest of your code if blk is nil

 

edit:

Ah, yes, its ssname that reports the error...

ssname expects a valid selection set (too)

 

(setq blk (ssget "x" (list (cons 0 "INSERT") (cons 2 "Title Block"))))

(if blk 

   (progn

      (setq revdate (LM:GetAttributeValue (ssname blk 0) "Rev_Date" ))

      ; add whatever else needs to be done

   )

; else

   (progn

      (princ "\nTitle block not found")

     ; add whatever you wish to be done

   )

)