Clint Posted March 19 Posted March 19 Goal: Find methods to help assemble a new LISP program or find an existing LISP program to perform the following: Convert all entities to layer zero while maintaining properties as originally assigned based on the entities' original layer. In a single DWG file, 700+/- details are organized and include drawing borders that supply individual details to our main non-Autodesk specialized and multi-functional design application. Please provide: Links to and/or actual LISP programs that perform this or similar conversions. LISP tips and/or instruction on links to methods to create a conversion LISP program. Non-programmed methods to accomplish this conversion. Skill level: LISP Beginner Quote
devitg Posted March 19 Posted March 19 @Clint Please upload a sample dwg with a few entities before and after 1 Quote
EnM4st3r Posted March 19 Posted March 19 (edited) i think this goes in the direction you want, but this does not change some dimension colors and similar things. Also it doesnt take the transparency value from the layer. I added comments on the side so you can understand whats supposed to happen (defun c:layZ (/ layerswap doc) ;| Sets object layer by string. Creates if neccessary @Param obj \<vla-obj> @Param str \<string> name of the layer the object should be set to. @Returns ? |; (defun layerswap (obj str / makelayer doc oldlayer oldlock) (defun makelayer (str / layers) (setq layers (vla-get-layers doc)) (if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list layers str)))) t (vla-add layers str) ) ) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (if (makelayer str) (progn (setq oldlayer (vla-item (vla-get-layers doc)(vla-get-layer obj))) (setq oldlock (vla-get-lock oldlayer)) (vla-put-lock oldlayer :vlax-false) (vla-put-layer obj str) (vla-put-lock oldlayer oldlock) ) ) );defun (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vlax-for item (vla-get-modelspace doc) ; goes trough every drawing object in model area (if (vlax-property-available-p item 'layer t) ; checks if item has the property "layer" (foreach property '("Color" "LineType" "LineWeight") (if (vlax-property-available-p item property t) ;checks if the item has property (vlax-put-property item property (vlax-get-property (vla-item (vla-get-layers doc)(vla-get-layer item)) property)) ;gets layer property and sets it to item ) ) ) (layerswap item "0") ; sets obj layer to 0 ) ) Edited March 19 by EnM4st3r 1 Quote
Clint Posted March 19 Author Posted March 19 THANKS!!! Last June, I stepped into a whole new industry and company where it appears there is varying degrees of CAD application sophistication. With other main duties, I was charged with helping convert details from CAD just yesterday. I was asked to introduce CAD task automation. As I now understand it, ALL ENTITIES are to be individual elements as BASIC lines (no polylines), arcs, circles, text, leaders, etc. Prepping several hundred details organized in model space only and within a SINGLE FILE by the person in charge, I was just charged with assisting conversion must meet the limitations of our main design application. EACH OF THE DETAILS ARE SAVED AS INDIVIDUAL FILES to an ASCII 11/12 DXF file format as well. One caveat: In the attached, Example for Post - Finished Detail, a free routine was used (just found by me yesterday) that converts dynamic blocks to static blocks. The parameters remain. How do you remove all parameters? Example for Post - Finished Detail.dxf Example for Post - Source Drawing to Convert (with Various Layers)l.dxf.dwg Quote
Clint Posted March 19 Author Posted March 19 I appreciate the inquiries and the excellent code just provided so far. It is my hope you will stay tuned as the code is tested and anwers are provided Further input is welcome by other sage members and a question or two posted by your lowly programming newbie and requestor. Quote
Clint Posted March 19 Author Posted March 19 1 hour ago, EnM4st3r said: i think this goes in the direction you want, but this does not change some dimension colors and similar things. Also it doesnt take the transparency value from the layer. I added comments on the side so you can understand whats supposed to happen (defun c:layZ (/ layerswap doc) ;| Sets object layer by string. Creates if neccessary @Param obj \<vla-obj> @Param str \<string> name of the layer the object should be set to. @Returns ? |; (defun layerswap (obj str / makelayer doc oldlayer oldlock) (defun makelayer (str / layers) (setq layers (vla-get-layers doc)) (if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list layers str)))) t (vla-add layers str) ) ) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (if (makelayer str) (progn (setq oldlayer (vla-item (vla-get-layers doc)(vla-get-layer obj))) (setq oldlock (vla-get-lock oldlayer)) (vla-put-lock oldlayer :vlax-false) (vla-put-layer obj str) (vla-put-lock oldlayer oldlock) ) ) );defun (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vlax-for item (vla-get-modelspace doc) ; goes trough every drawing object in model area (if (vlax-property-available-p item 'layer t) ; checks if item has the property "layer" (foreach property '("Color" "LineType" "LineWeight") (if (vlax-property-available-p item property t) ;checks if the item has property (vlax-put-property item property (vlax-get-property (vla-item (vla-get-layers doc)(vla-get-layer item)) property)) ;gets layer property and sets it to item ) ) ) (layerswap item "0") ; sets obj layer to 0 ) ) I added your program to the customized version of BricsCAD "on_start.lsp" file. Referring to the autoload statement below, I have a question about the ("")) . My current understanding is that inside the parentheses, a keyboard shortcut exists as it does in most other programs. Must the program code be changed to accommodate a 2 or 3-letter shortcut for yours? It appears that 'dusting off and hitting' the Auto/Visual LISP reference is a must for me. (autoload "Layz" ' ("")) ;Layer - Layer change to zero and retains original entity properties Quote
Clint Posted March 19 Author Posted March 19 Hi DevitG, BTW, KISS is alive and well: A simple EXPLODE operation took care of the PLINE-related parameter definitions remaining after exploding the static blocks. Eliminating a stubborn text style named "Ascent" and now in use by some "hidden" object/ object definition (?) but needing deletion will be the topic of my next inquiry here. Any ideas? Quote
BIGAL Posted March 20 Posted March 20 "hidden object" it may be text in a block so that is not obvious, a bit of a task to find, you can go through every block and check text style. Google not something I have. Understand where your at had to try and fix a dwt that one guy wanted to use he did not care if it gave error messages about text styles on opening as it worked. 1 Quote
EnM4st3r Posted March 20 Posted March 20 14 hours ago, Clint said: Referring to the autoload statement below, I have a question about the ("")) . ... (autoload "Layz" ' ("")) ;Layer - Layer change to zero and retains original entity properties Dont know about BrisCAD but i guess its the same as for autocad. The Syntax for autoload is: (autoload filename cmdlist) So example filename could be: "Z:/AutoLisp/Creations/LayZ.lsp" cmdlist is the command list, here you list the commands you want to autoload wich would just be this: '("LayZ") so the full autoload would be like that: (autoload "Z:/AutoLisp/Creations/Layz.lsp" '("LayZ")) ;Layer - Layer change to zero and retains original entity properties also what i noticed about that code, is that there is not check if the Properties the entity has is already indivudual, right now it always takes the layers property 1 Quote
EnM4st3r Posted March 20 Posted March 20 this version should only take the layer property if the property set is ByLayer (defun c:layZ (/ layerswap doc) ;| Sets object layer by string. Creates if neccessary @Param obj \<vla-obj> @Param str \<string> name of the layer the object should be set to. @Returns ? |; (defun layerswap (obj str / makelayer doc oldlayer oldlock) (defun makelayer (str / layers) (setq layers (vla-get-layers doc)) (if (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-item (list layers str)))) t (vla-add layers str) ) ) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (if (makelayer str) (progn (setq oldlayer (vla-item (vla-get-layers doc)(vla-get-layer obj))) (setq oldlock (vla-get-lock oldlayer)) (vla-put-lock oldlayer :vlax-false) (vla-put-layer obj str) (vla-put-lock oldlayer oldlock) ) ) ) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vlax-for item (vla-get-modelspace doc) ; goes trough every drawing object in model area (mapcar '(lambda (property layervalue) (if (and (vlax-property-available-p item property t) ;checks if the item has the property (= layervalue (vlax-get-property item property)) ;checks if item is ByLayer ) (vlax-put-property item property (vlax-get-property (vla-item (vla-get-layers doc)(vla-get-layer item)) property)) ;gets layer property and sets it to item ) ) '("Color" "LineType" "LineWeight"); Property '(256 "ByLayer" -1); Layervalue ) (layerswap item "0") ; sets obj layer to 0 ) ) 1 Quote
Recommended Posts
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.