Jump to content

create and load layer in acaddoc


jimpcfd

Recommended Posts

hi all

 

is it possible to create and load a Layer in acaddoc file, i have a layer that i use in most of our drawings called EDGE, it's color needs to be red, continuous line type and 0.0 lineweight, no bylayer in it. can anyone help ?

 

thanks

jimpcfd

Link to comment
Share on other sites

  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    5

  • pBe

    5

  • jimpcfd

    5

  • ReMark

    2

Top Posters In This Topic

Put this into your acaddoc.lsp

 


   (if (not (tblsearch "LAYER" "EDGE"))
     (entmake
       (list '(0 . "LAYER")
             '(100 . "AcDbSymbolTableRecord")
             '(100 . "AcDbLayerTableRecord")
             '(2 . "EDGE")
             '(6 .  "Continuous")
             '(62 . 1)'(370 . 0)
             '(70 . 0)
             
       )
     )
   )

Link to comment
Share on other sites

For sure the template solution sugested by ReMark is better; if still want to add it programatically:

 

(entmake '((0 . "LAYER")
          (100 . "AcDbSymbolTableRecord")
          (100 . "AcDbLayerTableRecord")
          (2 . "EDGE")
          (70 . 0)
          (62 . 1)
          (6 . "Continuous"))
)

Regards,

Mircea

Link to comment
Share on other sites

Both lisp routines are overkill. Put the layer in your template. It will always be there whether you need it or not. And if it really bothers you to have a layer that is not referenced then purge it along with all the other unreferenced entities.

Link to comment
Share on other sites

Both lisp routines are overkill. Put the layer in your template. It will always be there whether you need it or not.

 

Using a template will ensure the Layer is available in new drawings, but the layer will still not be accessible in existing drawings.

 

Creating the layer using the ACADDOC.lsp will ensure the Layer is available in both new and existing drawings.

Link to comment
Share on other sites

I would use something like this:

 

(
   (lambda ( data / ent )
       (if (setq ent (tblobjname "LAYER" (cdr (assoc 2 data))))
           (entmod (cons (cons -1 ent) data))
           (entmake data)
       )
   )
  '(
       (0 . "LAYER")
       (100 . "AcDbSymbolTableRecord")
       (100 . "AcDbLayerTableRecord")
       (70 . 0)
       (2 . "EDGE")
       (6 .  "Continuous")
       (62 . 1)
       (370 . 0)
   )
)

 

The above will create the Layer if it doesn't already exist in the drawing, or if it does exist, will modify the existing layer properties to match those required.

Link to comment
Share on other sites

i tried the DWT file options but, as Lee has said, the problem comes when you are using DXF's from other systems, as we do a lot.

of cause we could type dxfin all the time but , it's so much easier to just click on the file.

 

i didn't know that you could put Vlisp methods in acaddoc?

thanks tharwat,msasu and of cause Lee, i will have a play and see what's best for me.

 

thanks

Link to comment
Share on other sites

You're very welcome jimpcfd :thumbsup:

 

Note that the ACADDOC.lsp is simply like any another LISP file, except that it will load automatically for every drawing opened because of its filename.

 

When a drawing is opened, AutoCAD is programmed to search the Support File Directories and Working Directory (searches here first) for any LISP file named "ACADDOC.lsp" and will load the first one that it finds.

 

Hence, the ACADDOC.lsp can contain the same LISP expressions as any other LISP file. The ACADDOC.lsp could contain a whole program itself, or even multiple programs. However, it is usually far more manageable and maintainable to load programs from other LISP files via load expressions (these are also LISP expressions themselves) in the ACADDOC.lsp, so that each program has its own .lsp file.

 

Lee

Link to comment
Share on other sites

You could also load a layer with a button macro. Just click and layer created.

 

[size=2][color=black]^C^C_-layer;make;edge;color;red;;ltype;continuous;;lweight;0.0;;;[/color][/size]

 

You can also use tool palettes (my preference) and design center, I just prefer to load layers as needed.

Link to comment
Share on other sites

hi All, many thanks

the only problem i get is that the layer is a bylayer colour, which for us is a nightmare, as on of out CNC machines when reading a DXF file defaults all bylayer colours to white.

is there a way around this, can the layer have a colour that is not linked to the bylayer ?

 

thanks

jimpcfd

Link to comment
Share on other sites

So, are you saying that the entities from said layer EDGE had the color set as ByLayer and this isn't interpreted well by your CNC? Therefore you want to have the color set directly on entities. I'm afraid there is no way to control that from layer; what you can do instead is after the sketch is done use QSELECT to gather all entities from that layer and fix their color to red. Or, it you are looking to automate this step you can redefine the SAVE command to add the run of a small AutoLISP routine that will perform that fix prior to save.

 

Regards,

Mircea

Link to comment
Share on other sites

many thanks pBe that cracked it :D

so what does ce mean then?

thanks

jimpcfd

 

Current Entity Color

same goes for Linetypes CELTYPE and Lineweights CELWEIGHT and also for Linetype scales CELTSCALE

 

All system variables, that you can also include on your acaddoc.lsp

 

(setvar 'Cecolor "1")

Link to comment
Share on other sites

thanks again pBe, being able to do that in acaddoc.lsp will be very handy.:D

 

thanks

jmpcfd

 

You are welcome.

 

Glad I could help

 

Cheers :)

Link to comment
Share on other sites

If your Layers are set up correctly, another option might be to use the following code to set the Colour of all objects to the colour of the Layer on which each resides (not ByLayer):

 

(defun c:SetColours ( / a c e i l s x )
   (while (setq a (tblnext "LAYER" (null a)))
       (setq l (cons (cons (cdr (assoc 2 a)) (cons 62 (abs (cdr (assoc 62 a))))) l))
   )
   (if (setq s (ssget "_X"))
       (repeat (setq i (sslength s))
           (setq e (entget (ssname s (setq i (1- i))))
                 c (cdr (assoc (cdr (assoc 8 e)) l))
           )
           (if (setq x (assoc 62 e))
               (entmod (subst c x e))
               (entmod (append e (list c)))
           )
       )
   )
   (princ)
)

Link to comment
Share on other sites

I supposed a reactor would be too much to ask Lee.

For Entity creation commands: i.e. Line, Polyline....

 

Detect current layer color then set it to CECOLOR :)

will that be overkill Lee?

Link to comment
Share on other sites

I supposed a reactor would be too much to ask Lee.

For Entity creation commands: i.e. Line, Polyline....

 

Detect current layer color then set it to CECOLOR :)

will that be overkill Lee?

 

Maybe not too much overkill, but certainly very annoying to code since you would have to account for every entity creation command and check the required colour from the current layer, but also allow for when the user changes an entity's layer / colour independently and react on those events too, using perhaps Object Reactors monitoring every entity created... if you want to code it, be my guest ;)

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...