Jump to content

Layer Creater Lisp Routine Issue


waders

Recommended Posts

Hello all,

I found this lisp rountine and it loads layers into AutoCad from a .csv file. It works great for the most part but I'm having touble when I use the "Freeze" column it hangs up. I'm posting the lisp & csv file. Just remember to change where the csv file is located in the lisp. Thanks for the help.

Layer Creater.zip

Link to comment
Share on other sites

  • Replies 58
  • Created
  • Last Reply

Top Posters In This Topic

  • waders

    11

  • alanjt

    8

  • pBe

    8

  • BlackBox

    6

Top Posters In This Topic

Hello all,

I found this lisp rountine and it loads layers into AutoCad from a .csv file. It works great for the most part but I'm having touble when I use the "Freeze" column it hangs up. I'm posting the lisp & csv file. Just remember to change where the csv file is located in the lisp. Thanks for the help.

 

Works fine here in ACAD 2009

Autocad crashes when you invoke "Freeze" on the layer palette?

 

Ooops :o , now i know what you mean "Freeze column" , the column on the CSV file

 

So what exactly do you want to happen there anyway? you want some layers frozen upon loading?

Edited by pBe
Link to comment
Share on other sites

It looks like he is using the CSV file to create layers and the layer settings/information. Sweet....

 

Yeah, I have the same issue, it hangs when I edit the freeze column in the csv file. Not sure why it does that. Hopefully someone will be able to figure this out. I would like to use this. I could also see a Thaw column. I like the fact that it will overwrite the exisitng layers in the file if they have been modified.

 

- If all you have is a hammer, everything looks like a nail.

Link to comment
Share on other sites

Perhaps this will help (code written quickly):

 

(vl-load-com)

(defun BB:CSV->Layers (path / f *error* _extract _trim acDoc l layerTable
                      layerName layerItem layerDescription layerColor
                      layerLinetype layerLineweight layerPlottable
                      layerFreeze
                     )
 ;; Exampe: (BB:CSV->Layers "Z:\\my_layers_folder\\my_layers.csv")
 (if (and (findfile path)
          (setq f (open path "r"))
     )
   (progn

     ;; Error handler
     (defun *error* (msg)
       (vla-endundomark acDoc)
       (cond
         ((not msg))                                                   ; Normal exit
         ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
         ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
       )                                                               
       (if f
         (close f)
       )
       (princ)
     )

     ;; Line _extraction sub-function
     (defun _extract (l /)
       (substr l 1 (vl-string-search "," l))
     )

     ;; Line _trim sub-function
     (defun _trim (v /)
       (vl-string-subst "" (strcat v ",") l)
     )

     ;; Main code
     (vla-startundomark
       (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
     )
     (read-line f)                                                     ; <- Skip first line (headers)
     (setq layerTable (vla-get-layers acDoc))

     ;; Linetype check
     ;; <- Add linetype import code here, to avoid errors

     (while (/= nil (setq l (read-line f)))
       (progn

         ;; Layer check
         (setq layerItem
                (vla-add layerTable (setq layerName (_extract l)))
         )

         ;; Layer settings          
         (setq l (_trim layerName))
         (vla-put-description
           layerItem
           (setq layerDescription (_extract l))
         )
         (setq l (_trim layerDescription))
         (if (/= 7 (setq layerColor (_extract l)))
           (vla-put-color layerItem layerColor)
         )
         (setq l (_trim layerColor))
         (vla-put-linetype layerItem (setq layerLinetype (_extract l)))
         (setq l (_trim layerLinetype))
         (if
           (= "BYLAYER" (strcase (setq layerLineweight (_extract l))))
            (vla-put-lineweight layerItem aclnwtbylayer)
         )
         (setq l (_trim layerLineweight))
         (if (/= "YES" (strcase (setq layerPlottable (_extract l))))
           (vla-put-plottable layerItem :vlax-false)
         )
         (setq l (_trim layerPlottable))
         (if (/= "NO " (strcase (setq layerFreeze (_extract l))))
           (vla-put-freeze layerItem :vlax-true)
         )
       )
     )
     (setq f (close f))
     (*error* nil)
   )
 )
)

 

Please note the changes made in the .CSV file attached (simply change the .TXT file extension to .CSV).

ArchExist_revised.txt

Edited by BlackBox
Link to comment
Share on other sites

Hey RenderMan, Thanks for looking at this. But I'm not quite following you. Where am I suppose to put the .csv file path? Thanks

Link to comment
Share on other sites

... I'm not quite following you. Where am I suppose to put the .csv file path? Thanks

 

This routine requires an argument (a file path) to a .CSV file in this case, which has the previously attached column format.

 

For example:

 

Say you were to save the .CSV file(s) in a directory on the server, we'll assume Z:\\my_layers_folder\\ (note that LISP requires double back-slashes), and let's also assume a file name of my_layers.csv, then you would use this to import the layers contained in said .CSV file:

 

(RM:CSV->Layers "Z:\\my_layers_folder\\my_layers.csv")

 

Basically, this permits you to specify any .CSV file (with the same format), and quickly import *those* layers. You could setup a macro for each discipline (assuming they use different layers), or one for each client... whatever. It really depends on how you work, and what your needs are.

 

If it would be helpful, I can easily revise the routine to be 'hard-coded' for you, if this is the only .CSV file you'd ever need.

 

Hope this helps!

Link to comment
Share on other sites

ODBX import from existing drawing file...

 

(defun AT:ImportLayers (dwg / _catch col odbx odbxcol)
 ;; Import layers from specified drawing file
 ;; Alan J. Thompson

 (defun _catch (fnc lst / c)
   (if (not (vl-catch-all-error-p (setq c (vl-catch-all-apply fnc lst))))
     (cond (c)
           (T)
     )
   )
 )

 (or *Acad* (setq *Acad* (vlax-get-acad-object)))
 (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument *Acad*)))
 (if (and (setq dwg (findfile dwg))
          (setq col (vla-get-layers *AcadDoc*))
          (setq odbx
                 (_catch
                   'vla-GetInterfaceObject
                   (list *Acad* (strcat "ObjectDBX.AxDbDocument." (substr (getvar 'ACADVER) 1 2)))
                 )
          )
          (_catch 'vla-open (list odbx dwg))
     )
   (vlax-for obj (setq odbxcol (vla-get-layers odbx))
     (_catch 'vla-CopyObjects
             (list odbx
                   (vlax-safearray-fill (vlax-make-safearray vlax-vbObject (cons 0 0)) (list obj))
                   col
             )
     )
   )
 )
 (mapcar (function (lambda (o) (and o (_catch 'vlax-release-object o)))) (list odbxcol odbx))
)

eg.

(AT:ImportLayers "c:\\layers.dwg")

Link to comment
Share on other sites

Thanks - same to you :)

Thanks. It has its uses. Not nearly as versatile as your STEAL one, but I wrote this a while back and I only needed to bring in all layers. Speaking of, does the steal sub only allow for importing of named objects within a named collection, or will it import everything from a specified collection?

Link to comment
Share on other sites

Thanks. It has its uses. Not nearly as versatile as your STEAL one, but I wrote this a while back and I only needed to bring in all layers. Speaking of, does the steal sub only allow for importing of named objects within a named collection, or will it import everything from a specified collection?

 

Only named items I am afraid - I suppose it could be tweaked to import everything, but having originally set the program up with DCL in mind, the structure is geared for a selection of named items from a collection.

 

But to be honest, I am slightly disappointed with the latest version of the 'Steal' program - having developed it to try to suit everyone's needs, I think I may have 'over-developed' it. :unsure:

Link to comment
Share on other sites

Only named items I am afraid - I suppose it could be tweaked to import everything, but having originally set the program up with DCL in mind, the structure is geared for a selection of named items from a collection.

 

But to be honest, I am slightly disappointed with the latest version of the 'Steal' program - having developed it to try to suit everyone's needs, I think I may have 'over-developed' it. :unsure:

I figured. Just checking. Yeah, that can happen when posting to the masses. I have routines I use on a daily basis that I have options I don't even use just because I thought when I posted it someone might like it. Needless to say, I stopped doing that.
Link to comment
Share on other sites

Sorry for my limited knowledge but I am missing something.

 

If I understand correctly...this is what I have at the head of the code:

 

(defun RM:CSV->Layers (path / f *error* extract trim activeDoc l
layerTable layerName layerItem layerDescription
layerColor layerLinetype layerLineweight
layerPlottable layerFreeze)
;; © RenderMan 2011, CADTutor.net
;; Exampe: (RM:CSV->Layers "Z:\\my_layers_folder\\my_layers.csv")
(RM:CSV->Layers "H:\\acad\\AutoCad Custom Support Folder\\Lisp Files\\ArchExist.csv")
(vl-load-com)
(if (and (findfile path)
(setq f (open path "r")))

 

Is this correct? If so....what do I need to type at the command line to get this to run? (I do have it loaded in Appload.)

 

Laugh if you must, as I do feal a little dumb here but.....I have to ask none-the-less.......lol

Link to comment
Share on other sites

Put the call to the subroutine outside of the subroutine.

 

eg.

(defun _say (string) (princ "\nYou said: " string))

 

(_say "I like pizza.")

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...