Jump to content

Recommended Posts

Posted

I can't seem to set the created layer to current in this lisp. It does everything apart from that. Can some point me in the direction please?

 

 

(defun C:kerb ()
 (setq SUCE (getvar "cmdecho"))
 (setq SUOM (getvar "orthomode"))
 (setq SUSM (getvar "osmode"))
 (setq SUAB (getvar "angbase"))
 (setq SUAD (getvar "angdir"))
 (setq SUCL (getvar "clayer"))
 (setq SUCR (getvar "cecolor"))



(setq vl1 (list
	(cons 0 "LAYER")		;Name of entity
	(cons 100 "AcDbSymbolTableRecord")					;Open Records
	(cons 100 "AcDbLayerTableRecord")					;Locate Layer Table
	(cons 2 "CCC_LAYOUT_Proposed_Kerb_160mm")				;Name of Layer
	(cons 6 "Continuous")						;Linetype
	(cons 62 6)							;colour = light grey
	(cons 70 0)							;state
	(cons 290 1)							;1=plot, 0=Don't plot
		)							;End of entity list
	)
	(entmake vl1)

(setvar "clayer" "CCC_LAYOUT_Proposed_Kerb_160mm")  
(command "_.-layer" "_LW" "0.6" "CCC_LAYOUT_Proposed_Kerb_160mm" "")
(command "_-color" "bylayer")
(setvar "angbase" 0.0000)
 	(setvar "angdir"  0)
 	(setvar "orthomode" 0)
 	(setvar "plinegen" 1)
   	(setvar "osmode" 0)
   	(command "_.pline")
   	(setvar "osmode" 16383)


 (setvar "cmdecho" SUCE)
 (setvar "orthomode" SUOM)
 (setvar "osmode" SUSM)
 (setvar "angbase" SUAB)
 (setvar "angdir" SUAD)
 (setvar "clayer" SUCL)
 (setvar "cecolor" SUCR)
 (princ)

)

Posted
(defun c:KERB (/ *error*)
 (princ "\rKERB ")

 (defun *error* (msg)
   (and angbase (setvar 'angbase angbase))
   (and angdir (setvar 'angdir angdir))
   (and cecolor (setvar 'cecolor cecolor))
   (and clayer (setvar 'clayer clayer))
   (and cmdecho (setvar 'cmdecho cmdecho))
   (and orthomode (setvar 'orthomode orthomode))
   (and osmode (setvar 'osmode osmode))
   (and plinegen (setvar 'plinegen plinegen))
   (and acDoc (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
   )
   (princ)
 )

 ((lambda (acDoc angbase angdir cecolor clayer cmdecho orthomode osmode
           plinegen / layerName
          )
    (vla-startundomark acDoc)
    (if
      (not
        (tblsearch "layer"
                   (setq layerName "CCC_LAYOUT_Proposed_Kerb_160mm")
        )
      )
       (progn
         (setq oLayer (vla-add (vla-get-layers acDoc) layerName))
         (vla-put-lineweight oLayer acLnWt060)
       )
    )
    (setvar 'angbase 0.0000)
    (setvar 'angdir 0)
    (setvar 'cecolor "BYLAYER")
    (setvar 'clayer layerName)
    (setvar 'cmdecho 0)
    (setvar 'orthomode 0)
    (setvar 'osmode 16383)
    (setvar 'plinegen 1)
    (command "._pline")
    (while (= 1 (logand (getvar 'cmdactive) 1))
      (command PAUSE)
    )
    (*error* nil)
  )
   (vla-get-activedocument (vlax-get-acad-object))
   (getvar 'angbase)
   (getvar 'angdir)
   (getvar 'cecolor)
   (getvar 'clayer)
   (getvar 'cmdecho)
   (getvar 'orthomode)
   (getvar 'osmode)
   (getvar 'plinegen)
 )
)

Posted

Thanks Renderman. Appreciate the help!

Posted

@RM .

 

Is not it good idea to minimize all these system variables with mapcar to avoid all these extra lines of codes ?

 

(mapcar 'setvar <list of System variables > <New Values>)

Posted

Is not it good idea to minimize all these system variables with mapcar to avoid all these extra lines of codes ?

 

(mapcar 'setvar <list of System variables > <New Values>)

 

Certainly, the code I posted could use some improvement(s). However, rather than have the system variables, and their associated values in two separate lists, I find it easier to 'read' when they're together.

 

Consider these sample functions:

(setq layerName "0")

(defun _Mapcar ()
 (mapcar 'setvar
         '(angbase angdir cecolor clayer cmdecho orthomode osmode
           plinegen
          )
         (list 0.0000 0 "BYLAYER" layerName 0 0 16383 1)
 )
)

(defun _Foreach (/ error)
 (foreach x (list '(angbase 0.0000)
                  '(angdir 0)
                  '(cecolor "BYLAYER")
                  (list clayer layerName)
                  '(cmdecho 0)
                  '(osmode 16383)
                  '(plinegen 1)
            )
   (if (vl-catch-all-error-p
         (setq error (vl-catch-all-apply 'setvar x))
       )
     (prompt (strcat "\n** Error: "
                     (vl-catch-all-error-message error)
                     " ** "
             )
     )
   )
 )
)

 

... And the speed test:


_$ (bench '(_Mapcar _Foreach) '() 1000)

_MAPCAR
Elapsed: 5959
Average: 5.9590

_FOREACH
Elapsed: 5289
Average: 5.2890
_$ 

 

... Not to mention the _Foreach function's ability to handle an error object; food for thought. :beer:

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