Jump to content

Recommended Posts

Posted

I am trying to incoporate this command (setbylayer) into a lisp routine that I am making to clean up our xrefs. I am trying to adjust the settings to change only the color, select all objects in the drawing, change byblock to bylayer, and to include blocks. Any help would be appreciated.

Posted
I am trying to incoporate this command (setbylayer) into a lisp routine that I am making to clean up our xrefs. I am trying to adjust the settings to change only the color, select all objects in the drawing, change byblock to bylayer, and to include blocks. Any help would be appreciated.

 

For starters you could look into SETBYLAYERMODE variable.

 

 

SETBYLAYERMODE

 

Type: Integer

Saved in: Registry

Initial value: 127

 

From the AutoCAD Help Section under system variables.

 

Controls which properties are selected for SETBYLAYER

 

The setting is stored as an integer using the sum of the following values:

 

0 No properties are selected

1 Color property

2 Linetype property

4 Lineweight property

8 Material property

16 Plot Style property

32 Changes ByBlock to Bylayer

64 Includes blocks when changing ByBlock to ByLayer

 

There is also other information there not shown here.

 

Also look into ssget in the Developer Help Section

 

Creates a selection set from the selected object

 

(ssget [sel-method] [pt1 [pt2]]

[pt-list] [filter-list])

Selection sets can contain objects from both paper and model space, but when the selection set is used in an operation, ssget filters out objects from the space not currently in effect. Selection sets returned by ssget contain main entities only (no attributes or polyline vertices).

 

Maybe this thread will give you some idea:http://www.cadtutor.net/forum/showthread.php?t=42062&highlight=SET+BYLAYER+LISP

  • Like 1
Posted

How is this. (FYI - I am a novice at this stuff)

 

 
(defun c:cleanxref2 ()
  (command "setvar" "cmdecho" 0)(command "setbylayermode" "1")
  (command "setvar" "cmdecho" 0)(command "setbylayer" "all" "" "y" "y")(princ))

Posted

The setbylayer command doesn't seem to get dimensions that have the text set to a different color. Is there a setting in this command that can access all annotation items in a drawings as well as all the other items this command is changing to bylayer?

Posted
The setbylayer command doesn't seem to get dimensions that have the text set to a different color. Is there a setting in this command that can access all annotation items in a drawings as well as all the other items this command is changing to bylayer?

That because its part of a named dimstyle. In that case you would need to get a selection set of all dimensions and change the dimstyle variables of the named dimstyle to bylayer. Seems you will have some addtional coding to do.

 

 

Dimension Text: DIMCLRT

Dimension Lines: DIMCLRD

Dimension Ext Lines: DIMCLRE

Posted

ksperopoulos,

 

Below is a code that I found on Afralisp http://www.afralisp.net/archive/lisp/clay.htm that touches the subject of setting entities color properties to bylayer. There are other areas such as linetype and blocks to give you a better idea on how to proceed. Once you get the idea with this code, The rest should become easier I hope. Afralisp has a great way of explaining things in simple terms to make it easier to learn. For linetypes and blocks you can find coding on Afralisp as well. You can refine them to your need as you see fit.

 

This code deals with setting color on most general entities.

I just changed the long name from ColorToLayer.lsp to CTL.lsp.

;CODING BEGINS HERE

(defun c:CTL ()
 (setq i 0 n 0)                                            ;clear the loop control variables
 (prompt "\n Select entities to analyze ")                 ;prompt the user
 (setq sel (ssget))                                        ;get the selection set
 (setq n (sslength sel))                                   ;get the number of objects
 (repeat n                                                 ;start the loop
   (setq entity (ssname sel i))                            ;get the entity name
   (setq name (entget entity))                             ;now get the entity list
   (if (not (assoc 6 name))                                ;if not Bylayer
     (progn                                                ;do the following
       (setq layer (cdr (assoc 8 name)))                   ;retrieve the layer name
       (setq layerinf (tblsearch "LAYER" layer))           ;get the layer data
       (setq layercol (cdr (assoc 62 layerinf)))           ;extract the default layer colour
       (setq name (append name (list (cons 62 layercol)))) ;construct an append the new list
       (entmod name)                                       ;update the entity
       (entupd entity)                                     ;update the screen
     )                                                     ;progn
   )                                                       ;if
   (setq i (1+ i))                                         ;increment the counter
 )                                                         ;repeat
 (princ))                                                  ;defun
(princ)

;CODING END HERE 

Posted

Thanks Buzzard! I've got a lot to learn.

  • 13 years later...
Posted
On 6/13/2010 at 2:43 PM, ksperopoulos said:

How is this. (FYI - I am a novice at this stuff)

 

 

 
(defun c:cleanxref2 ()
  (command "setvar" "cmdecho" 0)(command "setbylayermode" "1")
  (command "setvar" "cmdecho" 0)(command "setbylayer" "all" "" "y" "y")(princ))
 

How would you write this if you wanted to do it on multiple files within the same folder?

 

Posted (edited)

You can write a SCRIPT that will open a dwg and run the 2 lines then close and save. A script is like writing down the commands that you manually type but can have lisp. Save script as a .scr file.

Not tested.

Open dwg1
(command "setbylayermode" "1")
(command "setbylayer" "all" "" "y" "y")
close y
Open dwg2
(command "setbylayermode" "1")
(command "setbylayer" "all" "" "y" "y")
close y
Open dwg3
(command "setbylayermode" "1")
(command "setbylayer" "all" "" "y" "y")
close y

Dont worry about cmdecho as screen will flash anyway.

 

Google Running scripts autocad

Edited by BIGAL

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