Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

AutoLisp Help 1

Status
Not open for further replies.

CDH

Structural
Jul 16, 2001
159
I am looking for a way to move an object to another layer, based on it's current layer. For example: Say I have a line on a layer called "1" I want to be able to select that line and automatically move it to another layer called "x-1" which may or may not exist. I would also like to be able to select more than one object at a time, and have them all go to other layers based on their current layers. "1" to "x-1", "2" to "x-2", "column" to "x-column", etc.

Whatever layer the object is on, take that name and create a new layer with an "X" prefix, or if the x-layer exists, just move it to that layer.

Does this all make sense?

I would like to do this myself, but haven't gotten this deep into lisp and need some direction to get started.
If anybody has ideas or anything, I would appreciate hearing them.

Thanks
Chris
 
Replies continue below

Recommended for you

I have a program that changes objects (except solids) on the lowest level possible using the DXF codes for the entities. You select the object, then specify the DXF group code, then a new value for that code. It will not add a non-existent group code to an object, but it will put an object on a layer that does not exist, effectively creating the layer for you. It is not exactly what you asked for but it is close. If you are not familiar with DXF group codes, you can look them up in the help file. Just a few for your info..

1 = text value (text string, attribute value)
2 = text value (block name, attribute info)
3 = text value (attribute info)
5 = handle (read only)
7 = text style
8 = layer
10 = point
11 = point
12 = point
40 = text size
62 = color (integer values only)
210 = point (ucs orientation)

There are many more, some the program will not modify, others it will without a hitch. It is very powerful, once you understand the DXF groups.

Send me an email so I can forward it to you if you want it.

lisper@-nospam-bcinc.hypermart.net

remove the -nospam- portion of the address

Cheers....
 
I wanted to improvise a lisp routine in an hour or so but turned out more involved than I thought. Still, hoping it may provide the starting hints, here is what I did: a routine to export the layer names to a txt file.
The next routine, to import layers from a txt file is incomplete. Maybe you can work on it.
Then, we need a routine to check if the layer exists.
Then, a routine to make selection sets by layers and change the layers.

Not simple...
Good luck


(defun C:LayerTranslate()
(princ "Statring to convert layers")

;(ExportLayerNames "LayerExport.txt")
;(GetLayerTranslation "LayerTranslate.txt")
;(ConvertLayersInDWG)


)
(defun ExportLayerNames(fileName)
(princ "Statring to convert layers")
)

(defun dxf (n ed) (cdr (assoc n ed)))
(defun C:ExportLayers()
;open LayerSource.txt to export layers of the current drawings
(setq mySource (open "LayerSource.txt" "w"))


;get all layers in the drawing
(setq onlayers (list ""))
(Print (strcat "2LayerName " "6LineType " "62Color "))
(print)
(setq layer1 (tblnext "LAYER" t))
;(print layer1)
;(dxf 2 layer1) is Layer Name
;(dxf 6 layer1) is linetype of the layer
;(dxf 62 layer1) is -1 for off layer, color for on layers. Like 3 for green
;(dxf 70 layer1) is 0 for normal layers, is 48 for XREF layers
(setq ThisLayer (list (dxf 2 layer1) (dxf 6 layer1) (dxf 62 layer1)))
(mapcar 'print Thislayer)
(princ "\"" mySource)
(princ Thislayer mySource)(princ "\"" mySource)(princ "\n" mySource)
(while (setq layer1 (tblnext "LAYER"))(progn
;(print layer1)
(setq ThisLayer (list (dxf 2 layer1) (dxf 6 layer1) (dxf 62 layer1)))
(mapcar 'print Thislayer)(print)
(princ "\"" mySource)
(princ Thislayer mySource)(princ "\"" mySource)(princ "\n" mySource)
))
(close mySource)
(findfile "LayerSource.txt")
)

(defun C:ImportLayers()
(setq mySource (open "LayerSource.txt" "r"))
(while (setq thisLayer (read-line mySource))
(if (strlen thislayer)(progn
(setq thisLayer (read thislayer))
(princ thisLayer)(princ "\n")
(princ (car (princ thisLayer)))
))
)
(close mySource)
)
 
Thanks for respoonding and for taking time to think about this. I kind of thought I might have to use dxf codes, however I have never done anything with them before. Maybe I should start with something a little more basic and keep adding to it:)
Anyway, thanks for the help, and if anyone else has other ideas, I would still like to see them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor