Jump to content

Automate Entity Conversion: Move Entities to Layer Zero Maintain Original Properties


Recommended Posts

Posted

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

 

 

Posted

@Clint Please upload a sample  dwg with a few entities before and after 

  • Like 1
Posted (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 by EnM4st3r
  • Like 1
Posted

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

Posted

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.

Posted
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 

Posted

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? 

Posted

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

  • Like 1
Posted
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

  • Like 1
Posted

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

 

  • Like 1

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