Jump to content

Recommended Posts

Posted

I usually create new layer by command function. Example:

(command "Layer" "N" MyLayer "L" MyLtype MyLayer "C" MyColor MyLayer "T" MyLayer "")

I'd like to do it by entmake function. Can anyone help me?

Thanks in advance!

Posted

(entmake (list (cons 0 "LAYER")
       (cons 100 "AcDbSymbolTableRecord")
       (cons 100 "AcDbLayerTableRecord")
       (cons 2 MyLayer)
       (cons 6 MyLtype)
       (cons 62 MyColor)
 )
)

read DXF reference for more group codes

Posted

If a layer MyLayer exist in dwg, you'll receive a error. You'd better use smth like this:

(defun create-my-layer (name ltype color / res)
                      ;|
*    Creates a new layer in current dwg.
* If layer exist, returns an ename-pointer to it (no changes). If not, layer
* has been tried to create with settings.
*    Call parameters:
name	Name of layer
ltype	Name of linetype setted to created layer. If it doesn't exist
	the linetype "Continuous" will be used
color	ICA-color for creating layer
|;
 (cond
   ((tblobjname "layer" "name"))
   (t
    (setq res (entmakex (list (cons 0 "LAYER")
                              (cons 100 "AcDbSymbolTableRecord")
                              (cons 100 "AcDbLayerTableRecord")
                              (cons 2 name)
                              (cons 6
                                    (cond ((tblobjname "ltype" ltype))
                                          (t "Continuous")
                                          ) ;_ end of cond
                                    ) ;_ end of cons
                              (cons 62 color)
                              ) ;_ end of list
                        ) ;_ end of entmakex
          ) ;_ end of setq
    )
   ) ;_ end of cond
 ) ;_ end of defun

Posted

Ssg

you need a layer to place something on it, right?

Why don't just create the desired object on the layer you need; if the layer exists- it will be used, if it doesn't exists -it will be created.

Posted

@kpblc: Thank you! I knew how to using conditional functions: if, cond…. I will add them in specific cases.

 

@fuccaro: Yes, but sometime I need to create new layers without any object (when creating template drawing with customize standards).

 

Thanks everybody! Your ideas are useful for me. But there is a question yet:

When I create a normal entity (line, circle, arc…) I don’t need DXF code 100.

Example:

(entmake (list (cons 0 "LINE") (cons 10 '(100 100)) (cons 11 '(150 200))))

 

AutoCAD application will automatically add them: AcDbEntity, AcDbLine, AcDbArc, AcDbCircle… to the entity database.

 

But why I must declare DXF code 100 with Layer (and maybe with all objects in Table Group)? Example:

(entmake (list (cons 0 "LAYER")

(cons 100 "AcDbSymbolTableRecord")

(cons 100 "AcDbLayerTableRecord")

(cons 2 "MyLayer")

(cons 70 0)

)

 

If one of them is missing, new layer will not be created.

Who can explain that?

  • 10 years later...
Posted (edited)
(defun create-my-layer (name ltype color / res)
                      ;|
*    Creates a new layer in current dwg.
* If layer exist, returns an ename-pointer to it (no changes). If not, layer
* has been tried to create with settings.
*    Call parameters:
name	Name of layer
ltype	Name of linetype setted to created layer. If it doesn't exist
	the linetype "Continuous" will be used
color	ICA-color for creating layer
|;
(cond
 ((tblobjname "layer" name))
 (t
  (setq res (entmake (list (cons 0 "LAYER")
                                     (cons 100 "AcDbSymbolTableRecord")
                                     (cons 100 "AcDbLayerTableRecord")
                                     (cons 2 name)
                                     (cons 70 0)
                                     (cons 62 color)
                                     (cons 6
                                           (cond ((tblobjname "ltype" ltype) ltype)
                                                    (t "Continuous")
                                      ) ;_ end of cond
                                     ) ;_ end of cons
                       ) ;_ end of list
            ) ;_ end of entmake
   ) ;_ end of setq
 )
) ;_ end of cond

) ;_end of defun

Edited by rkmcswain
added [CODE] tags
Posted
HERE's another that will let you add a layer description too. ... Oooops .. just realized this thread is over 10 years old :oops:
Posted
:)

*>>*

 

In my head they sounded like "AAaargh.. gimme routines!" :lol:

Posted
:)

*>>*

 

Hang on.. I think i recognized the one on the farthest left there...

 

Made you look!

Posted

:lol::lol::lol::lol:

Humurous Guys,

I knew, It is too late

  • 8 months later...
Posted (edited)

Hey.

Please help me, how can I put the text under the arrow?

(defun c:text_! ()
(while
(setq p1 (getpoint (strcat "\nFirst point  ->>")))
(setq p2 (getpoint p1 (strcat "\nSecond point  ->>")))

(setq      *ht* 0.5
           di (/ (* *ht* 0.45) 0.5)
           nm (trans '(0. 0. 1.) 1 0 t)
           )
(setq a (angle p1 p2))

(entmake
     (list
	 '(0 . "TEXT")
	 '(100 . "AcDbEntity")
	 '(100 . "AcDbText")
	 '(10 0. 0. 0.)
	 (cons 40 *ht*)
	 (cons 7 (getvar 'textstyle))
	 (cons 8 "Some layer")
	 (cons 62 1)
	 (cons 1 "Some string")
	 (cons 50
	       (if (minusp (cos a))
		 (+ pi a)
		 a
	       )
	 )
	 '(72 . 1) 
	  (cons 11 (mapcar '(lambda (x1 x2) (/ (+ x1 x2) 2.)) p1 p2))
	 '(73 . 1) 
       )
     ) ; end of entmake
	 
 (entmake
           (list
              '(0 . "LWPOLYLINE")
              '(100 . "AcDbEntity")
              '(100 . "AcDbPolyline")
              '(90 . 3)
              '(70 . 0)
               (cons 8 "Some layer")
			   (cons 10 (trans p2 1 nm))
              '(40 . 0.0)
               (cons 41 (/ di 2.0))
               (cons 62 21)
			   (cons 10 (trans (polar p2 (angle p2 p1) di) 1 nm))
               (cons 10 (trans p1 1 nm))
               (cons 210 nm)
           )
       ) ; end of entmake
)	 
(princ)	 
)

Sorry that the question is off topic

Edited by dilan

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