Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating either a Lisp or a script to change the pen weights

13 REPLIES 13
SOLVED
Reply
Message 1 of 14
Anonymous
903 Views, 13 Replies

Creating either a Lisp or a script to change the pen weights

Creating either a Lisp or a script to change the pen weights of two layer in autocad 2011?

13 REPLIES 13
Message 2 of 14
_Tharwat
in reply to: Anonymous

Hi

 

What are the pen weight values and what are the names of your layers ?

Message 3 of 14
Anonymous
in reply to: Anonymous

The layers are TL_TEXT pen .20 & TL_DIM pen .25. The existing pen weight is .09. Thanks
Message 4 of 14
_Tharwat
in reply to: Anonymous

Try this ..

 

(defun c:Test (/ ss i sn e)
  (foreach layer '(("TL_TEXT" 20) ("TL_DIM" 25))
    (if (tblsearch "LAYER" (car layer))
      (entmod
        (subst (cons 370 (cadr layer))
               (assoc 370
                      (setq e (entget (tblobjname "LAYER" (car layer))))
               )
               e
        )
      )
      (princ (strcat "Layer not found < " (car layer) " > ..."))
    )
  )
  (princ)
)

 

Message 5 of 14
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:
The layers are TL_TEXT pen .20 & TL_DIM pen .25. The existing pen weight is .09. Thanks

I think it can be as simple as -- in Lisp terms:

 

(command "_.layer" "_lw" 0.2 "TL_TEXT" "_lw" 0.25 "TL_DIM" "")

 

or in Macro terms:
 

^C^C_.layer _lw 0.2 TL_TEXT _lw 0.25 TL_DIM ;

 

or in Script terms:
 

_.layer _lw 0.2 TL_TEXT _lw 0.25 TL_DIM

 

followed by a blank line.

Kent Cooper, AIA
Message 6 of 14
_Tharwat
in reply to: Kent1Cooper


@Kent1Cooper wrote:

I think it can be as simple as -- in Lisp terms:

 


Is not it good idea to check if the layer name is existed first in the drawing and after that implement the actions

that is needed ?

 

 

Message 7 of 14
Kent1Cooper
in reply to: _Tharwat


@_Tharwat wrote:
....
Is not it good idea to check if the layer name is existed first in the drawing and after that implement the actions that is needed ? 

It doesn't hurt, but it's not necessary.  This is another situation in which the (command) function simplifies things considerably.  You may not be able to assign a lineweight to a non-existent Layer using (subst)/(entmod), but doing this with a Layer command, if either Layer doesn't exist, it will simply send a message: "No matching Layer names found."  Then it will just go back to the Layer prompt and continue, without error.  Whichever of those two Layers exists will have its lineweight assigned, and if either or both don't exist, it simply won't have found anything to assign the particular lineweight to.

Kent Cooper, AIA
Message 8 of 14
BlackBox_
in reply to: _Tharwat


@_Tharwat wrote:

Try this ..

 

(defun c:Test (/ ss i sn e)
  (foreach layer '(("TL_TEXT" 20) ("TL_DIM" 25))
    (if (tblsearch "LAYER" (car layer))
      (entmod
        (subst (cons 370 (cadr layer))
               (assoc 370
                      (setq e (entget (tblobjname "LAYER" (car layer))))
               )
               e
        )
      )
      (princ (strcat "Layer not found < " (car layer) " > ..."))
    )
  )
  (princ)
)

 


Perhaps this instead?

 

(defun c:FOO (/ layerName eName eData)
  (foreach layerItem '(("TL_TEXT" 20) ("TL_DIM" 25))
    (if (setq eName (tblobjname "layer" (setq layerName (car layerItem))))
      (entmod
        (subst (cons 370 (cadr layerItem))
               (assoc 370 (setq eData (entget eName)))
               eData
        )
      )
      (princ (strcat "Layer not found < " layerName " > ..."))
    )
  )
  (princ)
)

 



"How we think determines what we do, and what we do determines what we get."

Message 9 of 14
_Tharwat
in reply to: BlackBox_


@BlackBoxCAD wrote:


Perhaps this instead?

 


Maybe the use of word ANOTHER is much more suitable than INSTEAD since mine is not wrong . Smiley Wink

Message 10 of 14
Anonymous
in reply to: Anonymous

Thanks!
Message 11 of 14
BlackBox_
in reply to: _Tharwat


@_Tharwat wrote:

@BlackBoxCAD wrote:


Perhaps this instead?

 


Maybe the use of word ANOTHER is much more suitable than INSTEAD since mine is not wrong . Smiley Wink


Tharwat, my friend -

 

While the word 'perhaps' should have been sufficient, you may substitute with whatever word you like.

 

Just for clarification though... Did you, earlier today in another thread, inform someone that they obtained the ActiveDocument Object twice?

 

 

That code wasn't "wrong" either, but was somewhat redundant, and so you felt compelled to point that out, right?

 

I've done the same thing here, as you redundantly check for a Layer Table Record via TblSearch, and then obtain the Entity Name for same via TblObjName when all I did was use the latter as my 'check' given that if no record (symbol) is found, Nil is returned:

_$ (tblobjname "layer" "foo")
nil
_$ 

 

 

For the record, not once, have I called others' offering(s) "wrong," unless blatently missing the point (i.e., posted the wrong code in the wrong thread by mistake, etc.)... I'd like to believe that you know me well enough by now, that you understand no offense was intended here, only encouragement to refine our methods.

 

Cheers



"How we think determines what we do, and what we do determines what we get."

Message 12 of 14
_Tharwat
in reply to: BlackBox_


@BlackBoxCAD wrote:

@_Tharwat wrote:

@BlackBoxCAD wrote:


Perhaps this instead?

 


Maybe the use of word ANOTHER is much more suitable than INSTEAD since mine is not wrong . Smiley Wink


Tharwat, my friend -

 

While the word 'perhaps' should have been sufficient, you may substitute with whatever word you like.

 

Just for clarification though... Did you, earlier today in another thread, inform someone that they obtained the ActiveDocument Object twice?

 

 

That code wasn't "wrong" either, but was somewhat redundant, and so you felt compelled to point that out, right?

 

I've done the same thing here, as you redundantly check for a Layer Table Record via TblSearch, and then obtain the Entity Name for same via TblObjName when all I did was use the latter as my 'check' given that if no record (symbol) is found, Nil is returned:

_$ (tblobjname "layer" "foo")
nil
_$ 

 

 

For the record, not once, have I called others' offering(s) "wrong," unless blatently missing the point (i.e., posted the wrong code in the wrong thread by mistake, etc.)... I'd like to believe that you know me well enough by now, that you understand no offense was intended here, only encouragement to refine our methods.

 

Cheers


Completely right .

 

I have to admit that I did not pay my attention to the function TblObjName that it could behave the same as TblSearch function .

 

Thank you for the nice reply . Smiley Happy

Message 13 of 14
BlackBox_
in reply to: Anonymous

That is kind of you to say, my friend.

No matter what forum, or the nature of any potential disagreement, I would like to believe that we are all here to learn, help others, or both.

Should I ever act in a way in conflict with this stated belief, I fully expect others to confront me on it, and I will gladly do the same in kind.

I am far from an expert, yet am blessed to have accomplished what I have in, what I consider to be, such a short period of time. I would not have been able to do so without firstly the kindness of others (which is often more crticial, directive, or instructing than actually kind), and from understanding one simple fact (my old signature):

"Those who are offended by truth have no place among those who seek wisdom" - BlackBox (aka RenderMan)

Cheers, Tharwat :beer:


"How we think determines what we do, and what we do determines what we get."

Message 14 of 14
mid-awe
in reply to: BlackBox_


@BlackBoxCAD wrote:

@_Tharwat wrote:

Try this ..

 

(defun c:Test (/ ss i sn e)
  (foreach layer '(("TL_TEXT" 20) ("TL_DIM" 25))
    (if (tblsearch "LAYER" (car layer))
      (entmod
        (subst (cons 370 (cadr layer))
               (assoc 370
                      (setq e (entget (tblobjname "LAYER" (car layer))))
               )
               e
        )
      )
      (princ (strcat "Layer not found < " (car layer) " > ..."))
    )
  )
  (princ)
)

 


Perhaps this instead?

 

(defun c:FOO (/ layerName eName eData)
  (foreach layerItem '(("TL_TEXT" 20) ("TL_DIM" 25))
    (if (setq eName (tblobjname "layer" (setq layerName (car layerItem))))
      (entmod
        (subst (cons 370 (cadr layerItem))
               (assoc 370 (setq eData (entget eName)))
               eData
        )
      )
      (princ (strcat "Layer not found < " layerName " > ..."))
    )
  )
  (princ)
)

 


Not to say this is not a good way to do it, because it is. 

 

For an alternate approach, I choose to create a layer with the settings that I prefer and then use merge layer. Although, I have customized the Layer manager for isolating groups of layer for display within model space. All of my pages are set up with viewports to reflect managed layer groups.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost