Jump to content

dimension style create (plz chk my new lisp & how to improve)


autolisp

Recommended Posts

Kind of off topic but still related.

 

FWIW, technically speaking you dont really need to search the database for a layer name with entmake. However, you would if you needed to decide to either use ENTMAKE or ENTMOD something like the following:

 

(defun DSTYLE3_LAYER_CREATE (LNAM$ LCLR# LTYP$ LWGT# #prog)
(if (null (tblsearch "layer" LNAM$))
(set '#prog (lambda ( x ) (entmake x)))
(set '#prog (lambda (x / ent y)
(setq LNAM$ "TestLayer2")
(setq ent (entget (tblobjname "LAYER" LNAM$)))
(foreach y x
(if (not (member (car y) '(0 100 2)))
(setq ent (subst y (assoc (car y) ent) ent))))
(entmod ent) )))
(#prog
(list
(cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 2 LNAM$)
(cons 6 LTYP$)
(cons 62 LCLR#)
(cons 70 0)
(cons 290 1)
(cons 370 LWGT#)
)
)
(princ)
)

 

So using this...

 

(DSTYLE3_LAYER_CREATE "Test-Layer" 1 "Continuous" 18)
;; would create the layer
(DSTYLE3_LAYER_CREATE "Test-Layer" 2 "Continuous" 18)
;; would override the current layer def.

 

Se7en,

 

I am not sure that I understand you correctly, But don't you need to check for the existence of the layer before making it in any case?

Link to comment
Share on other sites

  • Replies 37
  • Created
  • Last Reply

Top Posters In This Topic

  • The Buzzard

    19

  • autolisp

    9

  • Se7en

    8

  • MSasu

    1

Top Posters In This Topic

Posted Images

ENTMAKE wont REmake the layer; let me set up a test for you.

 

Ok, So you are saying in the code I posted, Its basicly useless.

Link to comment
Share on other sites

no, why would it be useless? ...and BTW IMO nothing is useless!

 

I am sorry, I thought thats what you were implying. My mistake.

Link to comment
Share on other sites

...oops, and it looks like i forgot the slash in the arg list "(LNAM$ LCLR# LTYP$ LWGT# / #prog)" too.

 

here is the test:

(defun DSTYLE3_LAYER_CREATE (LNAM$ LCLR# LTYP$ LWGT# / #prog)
;;;  (if (null (tblsearch "layer" LNAM$))
;;;    (set '#prog (lambda ( x ) (entmake x)))
;;;    (set '#prog (lambda (x / ent y)
;;;                  (setq ent (entget (tblobjname "LAYER" LNAM$)))
;;;                  (foreach y x
;;;                           (if (not (member (car y) '(0 100 2)))
;;;                             (setq ent (subst y (assoc (car y) ent) ent))))
;;;                  (entmod ent) )))
;;;  (#prog
;;;
;;; commented out for test reasons.

 (entmake
  (list
    (cons 0   "LAYER")
    (cons 100 "AcDbSymbolTableRecord")
    (cons 100 "AcDbLayerTableRecord")
    (cons 2    LNAM$)
    (cons 6    LTYP$)
    (cons 62   LCLR#)
    (cons 70   0)
    (cons 290  1)
    (cons 370  LWGT#)
    )
  )
;;; (princ)
;;; un commented so we can see what entmake will return
)


(DSTYLE3_LAYER_CREATE "Test-Layer" 1 "Continuous" 18)
;; would create the layer
;; and entmake will return the ent list...
;;
(DSTYLE3_LAYER_CREATE "Test-Layer" 2 "Continuous" 18)
;; entmake will not re-create the layer and just returns nil.

Link to comment
Share on other sites

Alright here is the second part of the test code.

(defun DSTYLE3_LAYER_CREATE (LNAM$ LCLR# LTYP$ LWGT# / #prog)
 (if (null (tblsearch "layer" LNAM$))
   (set '#prog (lambda ( x ) (entmake x)))
   (set '#prog (lambda (x / ent y)
                 (setq ent (entget (tblobjname "LAYER" LNAM$)))
                 (foreach y x
                          (if (not (member (car y) '(0 100 2)))
                            (setq ent (subst y (assoc (car y) ent) ent))))
                 (entmod ent) )))
 (#prog
;;;  (entmake
;;;
;;; commented out for test reasons.
  (list
    (cons 0   "LAYER")
    (cons 100 "AcDbSymbolTableRecord")
    (cons 100 "AcDbLayerTableRecord")
    (cons 2    LNAM$)
    (cons 6    LTYP$)
    (cons 62   LCLR#)
    (cons 70   0)
    (cons 290  1)
    (cons 370  LWGT#)
    )
  )
;;; (princ)
;;; un commented so we can see what entmake will return
)


(DSTYLE3_LAYER_CREATE "Test-Layer" 1 "Continuous" 18)
;; would create the layer
;; and entmake will return the ent list...
;;
(DSTYLE3_LAYER_CREATE "Test-Layer" 2 "Continuous" 18)
;; since entmake will not re-create the layer and just returns nil
;; we substitue the command to call enmake with a set of process
;; using entmod instead to redefine an existing layer.

Link to comment
Share on other sites

Ok, I get your point. On the second layer call it did not overwrite the layer color from the first.

 

yeah. you got it.

its because entmake will not recreate the layer.

Link to comment
Share on other sites

yeah. you got it.

its because entmake will not recreate the layer.

 

Ok, But in the second situation it did modify the layer color. I see what you mean now. Thanks for that.

Link to comment
Share on other sites

no prob.

 

Just so you know, you will still have to take a closer look and fix all my typo's in the example(s) i gave you because i didnt spend a whole lot of time typing and checking it (I just whipped it up as a conversation piece).

Link to comment
Share on other sites

Not to stir-up a debate, But when I used it in my code it was only to avoid running the layer function if it was not needed even if it does not overwrite the layer. But this was still interesring all the same.

 

Thanks for the lesson.

Link to comment
Share on other sites

I kinda gleaned that (your intension's) from your code (thats why its not useless; it keeps ENTMAKE from even executing if the layer does exist) but, little details like this can make your code more robust for the end users. However, and this is a big "however", you need to keep these tricks well documented and segregated in your code lib's or create "black-box" type of procedures so that these sub procedures dont screw up some thing else. Trust me, i have dozens of lisp files i haven't even been able to clean up (and ive been here for three years) from my predecessor whom i now believe was addicted to crack or maybe even just a crack-pot! I spent months just replacing 20-30 line utility procedures (bloated code) with simple "one-liners"; I'm still finding mistakes.

Link to comment
Share on other sites

I am still in my learning stage, But certain things that I pick up along the way I try to retain. Do not get me wrong, I am not trying to be a lisp programmer by any means. I would have moved on to other areas of it by now, But I stick with certain things for the primary reason of being some kind of help to customize AutoCAD for certain areas, And I am content with this. There is always room to learn something new, But its not a pressing issue with me. I will try not to bark in area that I am not familiar with unless there it is something to help improve the current knowledge I have gotton so far.

 

I like how you approached it and were not critical over how I did this code. You had something to offer and I appreciate that.

Thanks

Link to comment
Share on other sites

...oops, and it looks like i forgot the slash in the arg list "(LNAM$ LCLR# LTYP$ LWGT# / #prog)" too.

 

here is the test:

(defun DSTYLE3_LAYER_CREATE (LNAM$ LCLR# LTYP$ LWGT# / #prog)
;;; (if (null (tblsearch "layer" LNAM$))
;;; (set '#prog (lambda ( x ) (entmake x)))
;;; (set '#prog (lambda (x / ent y)
;;; (setq ent (entget (tblobjname "LAYER" LNAM$)))
;;; (foreach y x
;;; (if (not (member (car y) '(0 100 2)))
;;; (setq ent (subst y (assoc (car y) ent) ent))))
;;; (entmod ent) )))
;;; (#prog
;;;
;;; commented out for test reasons.

(entmake
(list
(cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 2 LNAM$)
(cons 6 LTYP$)
(cons 62 LCLR#)
(cons 70 0)
(cons 290 1)
(cons 370 LWGT#)
)
)
;;; (princ)
;;; un commented so we can see what entmake will return
)


(DSTYLE3_LAYER_CREATE "Test-Layer" 1 "Continuous" 18)
;; would create the layer
;; and entmake will return the ent list...
;;
(DSTYLE3_LAYER_CREATE "Test-Layer" 2 "Continuous" 18)
;; entmake will not re-create the layer and just returns nil.

dear se7en

i test u r code but some error

Command: dstyle3

; error: no function definition: DSTYLE3_DIMSTYLE_CREATE

Link to comment
Share on other sites

dear se7en

i test u r code but some error

Command: dstyle3

; error: no function definition: DSTYLE3_DIMSTYLE_CREATE

 

Your welcome for the code autolisp, But the code that Se7en supplied was a test procedure for dealing with layers in different ways only and is not a dimension code at all. It does work, But you need to set it up properly.

Link to comment
Share on other sites

Your welcome for the code autolisp, But the code that Se7en supplied was a test procedure for dealing with layers in different ways only and is not a dimension code at all. It does work, But you need to set it up properly.

dear sir

thx agian for help me

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