Jump to content

How to Insert the Layer?Using Lisp?


Guest balajibth84

Recommended Posts

Guest balajibth84

Hai Here Balaji.Now i have the Code for the Layer Change.While i am using this code in that time that code Layer is not available means this code will not work.In that time i want Create that Layer automatically.So how to Create that Layer here?

 

(defun c:Test()

(setq set1(ssget))

(command "change" set1 "" "p" "la" "Test" ""))

 

While i am using this Code Test layer is Not available means its need to create automatically.So how to edit this code for that???Plz help me...Colour lineweight just fix default....

Link to comment
Share on other sites

Use the tblsearch function to look for the layer before you attempt to make any changes. If it is there then proceed if not make the layer.

 

 

 
(if (not(tblsearch "layer" "TEST"))
(command "-layer" "New" "TEST" "")
);_if

Link to comment
Share on other sites

Its better to use entmake

 

(defun makelay (LName LColor LType)
;  CAB
 (if (not(tblsearch "LAYER" LName))
   (entmake (list
              '(0 . "LAYER")
              '(100 . "AcDbSymbolTableRecord")
              '(100 . "AcDbLayerTableRecord")
              (cons 2  LName) ;layer name
              (cons 6  (if (and ltype(tblobjname "ltype" ltype)) ltype  "Continuous")) ;linetype
              (cons 62  LColor) ;layer color
              '(70 . 0) ; on, unlocked, thawed
            )
   )
 )
)

Link to comment
Share on other sites

Its better to use entmake

 

(defun makelay (LName LColor LType)
;  CAB
 (if (not(tblsearch "LAYER" LName))
   (entmake (list
              '(0 . "LAYER")
              '(100 . "AcDbSymbolTableRecord")
              '(100 . "AcDbLayerTableRecord")
              (cons 2  LName) ;layer name
              (cons 6  (if (and ltype(tblobjname "ltype" ltype)) ltype  "Continuous")) ;linetype
              (cons 62  LColor) ;layer color
              '(70 . 0) ; on, unlocked, thawed
            ) )  )
)

 

Thanks for that asos2000.

 

I tried to make it with Hidden lType but it does not concider it . Can you please tell me why ?

 

 

(defun makelay (LName LColor LType)
;  CAB
 (if (not(tblsearch "LAYER" LName))
   (entmake (list
              '(0 . "LAYER")
              '(100 . "AcDbSymbolTableRecord")
              '(100 . "AcDbLayerTableRecord")
              (cons 2  LName) ;layer name
              (cons 6  (if (and ltype(tblobjname "ltype" ltype)) ltype  "[color="red"][b]Continuous[/b][/color]")) ;linetype
              (cons 62  LColor) ;layer color
              '(70 . 0) ; on, unlocked, thawed
            ) ) ))

(makelay "My own Layer" 212 "[b][color="red"]Hidden[/color][/b]")

 

It makes the layer but with continuous lType. Also I have change it in the (if (and ltype(tblobjname "ltype" ltype)) ltype "Hidden"))

So it does not work or make the layer ???

 

Do you have any idea ?

Link to comment
Share on other sites

Give this a try

 

(defun makelay (LName LColor LType)
;  CAB
 (vl-load-com)
 (if (not (tblsearch "LTYPE" LType))
   (vla-load
     (vla-get-Linetypes
       (vla-get-ActiveDocument
         (vlax-get-acad-object))) LType "acadiso.lin"))  
 
 (if (not(tblsearch "LAYER" LName))
   (entmake (list
              '(0 . "LAYER")
              '(100 . "AcDbSymbolTableRecord")
              '(100 . "AcDbLayerTableRecord")
              (cons 2  LName) ;layer name
              (cons 6  (if (and ltype(tblobjname "ltype" ltype)) ltype  "Continuous")) ;linetype
              (cons 62  LColor) ;layer color
              '(70 . 0) ; on, unlocked, thawed
            ) ) ))

Link to comment
Share on other sites

Just for clarity, also make sure you're using the correct linetype definitions. You can do so through checking the Measurement Sysvar, so change the following line:

          (vlax-get-acad-object))) LType "acadiso.lin"))

to

          (vlax-get-acad-object))) LType (if (= (getvar "MEASUREMENT") 0) "acad.lin" "acadiso.lin")))

.

Link to comment
Share on other sites

Give this a try

(defun makelay (LName LColor LType)
;  CAB
 (vl-load-com)
 (if (not (tblsearch "LTYPE" LType))
   (vla-load
     (vla-get-Linetypes
       (vla-get-ActiveDocument
         (vlax-get-acad-object))) LType "acadiso.lin"))  
 (if (not(tblsearch "LAYER" LName))
   (entmake (list
              '(0 . "LAYER")
              '(100 . "AcDbSymbolTableRecord")
              '(100 . "AcDbLayerTableRecord")
              (cons 2  LName) ;layer name
              (cons 6  (if (and ltype(tblobjname "ltype" ltype)) ltype  "Continuous")) ;linetype
              (cons 62  LColor) ;layer color
              '(70 . 0) ; on, unlocked, thawed
            ) ) ))

 

Thanks a lot it works well now.

 

Regards

Link to comment
Share on other sites

Just for clarity, also make sure you're using the correct linetype definitions. You can do so through checking the Measurement Sysvar, so change the following line:
          (vlax-get-acad-object))) LType "acadiso.lin"))

to

          (vlax-get-acad-object))) LType (if (= (getvar "MEASUREMENT") 0) "acad.lin" "acadiso.lin")))

.

 

That's really great point. to set the LTypes file according to the two types of measurements of the current dwaring.

 

Thank you

Link to comment
Share on other sites

Just for clarity, also make sure you're using the correct linetype definitions. You can do so through checking the Measurement Sysvar, so change the following line:
          (vlax-get-acad-object))) LType "acadiso.lin"))

to

          (vlax-get-acad-object))) LType (if (= (getvar "MEASUREMENT") 0) "acad.lin" "acadiso.lin")))

.

 

Here's what I use :)

 

;;--------------------=={ Load Linetype }==-------------------;;
;;                                                            ;;
;;  Attempts to load a specified linetype from any linetype   ;;
;;  definition files (.lin) found in the ACAD Support Path    ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  lt - name of linetype to load                             ;;
;;------------------------------------------------------------;;
;;  Returns:  T if linetype loaded successfully, else nil     ll
;;------------------------------------------------------------;;

(defun LM:LoadLinetype ( lt / acapp acdoc aclts ) (vl-load-com)
 ;; © Lee Mac 2010
 
 (cond
   ( (tblsearch "LTYPE" lt) )
   ( (progn
       (setq acdoc (vla-get-ActiveDocument (setq acapp (vlax-get-acad-object)))
             aclts (vla-get-Linetypes acdoc))

       (vl-some
         (function
           (lambda ( file )
             (vl-catch-all-apply 'vla-load (list aclts lt file))
             (and (tblsearch "LTYPE" lt))
           )
         )
         (apply 'append
           (mapcar '(lambda ( directory ) (vl-directory-files directory "*.lin" 1))
             (LM:str->lst
               (vla-get-SupportPath (vla-get-Files (vla-get-Preferences acapp))) ";"
             )
           )
         )
       )
     )
   )
 )  
)

;;-------------------=={ String to List }==-------------------;;
;;                                                            ;;
;;  Separates a string into a list of strings using a         ;;
;;  specified delimiter string                                ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  str - string to process                                   ;;
;;  del - delimiter by which to separate the string           ;;
;;------------------------------------------------------------;;
;;  Returns:  A list of strings                               ;;
;;------------------------------------------------------------;;

(defun LM:str->lst ( str del / pos )
 ;; © Lee Mac 2010
 (if (setq pos (vl-string-search del str))
   (vl-remove "" (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del)))
   (list str)
 )
)

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