Jump to content

Which best way of create layer ????


autolisp

Recommended Posts

Dear all

Plz advice which is best method of create layer inside the lisp

1st

  (setq oldlayer (getvar "CLAYER"))
     (if (tblsearch "LAYER" "Dr")
(setvar "CLAYER" "Dr")
(command ".LAYER" "M" "Dr" "C" "6" "" "")
     )
(setvar "CLAYER" oldlayer)

 

2nd

(if (not (tblsearch "layer" "dr"))
(progn(command ".LAYER" "M" "dr" "C" "50" "" "")))

Link to comment
Share on other sites

I guess this is one of the best ..

 

(if (not (tblsearch "LAYER" "Dr"))
 (entmake (list (cons 0 "LAYER")
                (cons 100 "AcDbSymbolTableRecord")
                (cons 100 "AcDbLayerTableRecord")
                (cons 2 "Dr")
                (cons 70 0)
                (cons 62 6)
                           ))
 )

 

Tharwat

Link to comment
Share on other sites

I guess this is one of the best ..

 

(if (not (tblsearch "LAYER" "Dr"))
 (entmake (list (cons 0 "LAYER")
                (cons 100 "AcDbSymbolTableRecord")
                (cons 100 "AcDbLayerTableRecord")
                (cons 2 "Dr")
                (cons 70 0)
                (cons 62 6)
                           ))
 )

 

Tharwat

dear sir

thx for suggestion

Link to comment
Share on other sites

If you really want in insure setting to a layer:

;++++++++++++ Make Layer Current +++++++++++++++++++++++++++++++++
(defun SetLayer (name / ldef flag)
 (cond ((or (not name)
            (not (snvalid name)))
        (princ "\nBad Aurgment Passed To SetLayer - ")
        (prin1 name)
        (exit)))
 (command "_.LAYER")
 (if (not (tblsearch "LAYER" name))
     (command "_Make" name)
     (progn
       (setq ldef (tblsearch "LAYER" name)
             flag (cdr (assoc 70 ldef)))
       (and (= (logand flag  1)  1)
            (command "_Thaw" name))
       (and (minusp (cdr (assoc 62 ldef)))
            (command "_On" name))
       (and (= (logand flag  4)  4)
            (command "_Unlock" name))
       (and (= (logand flag 16) 16)
            (princ "\nCannot Set To XRef Dependent Layer")
            (quit))
       (command "_Set" name)))
 (command "")
 name)

 

-David

Link to comment
Share on other sites

Building on David's example... this uses ActiveX:

 

(defun SetLayer2  (layerName / activeDoc layerTable layerItem)
 (vl-load-com)
 (vla-startundomark
   (setq activeDoc (vla-get-activedocument (vlax-get-acad-object))))
 (if (= 'STR (type layerName))
   (if (not (vl-string-search "|" layerName))
     (progn
       (setq layerTable (vla-get-layers activeDoc))
       (if (tblsearch "layer" layerName)
         (progn
           (setq layerItem (vla-item layerTable layerName))
           (vla-put-freeze layerItem :vlax-false))
           (vla-put-layeron layerItem :vlax-true)
           (vla-put-lock layerItem :vlax-false)
         (setq layerItem (vla-add layerTable layerName)))
       (vla-put-activelayer activeDoc layerItem))
     (prompt "\n  <!>  Cannot Set to Xref Dependent Layer  <!> "))
   (progn
     (prompt "\n  <!>  Invalid Argument - ")
     (prin1 name)
     (prompt "  <!> ")))
 (vla-endundomark activeDoc)
 (princ))

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