TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Serge J. Gianolla on April 13, 2010, 11:15:20 PM

Title: Layer vs -Layer issue
Post by: Serge J. Gianolla on April 13, 2010, 11:15:20 PM
When in Layer Manager dialogue box, if you highlight one layer and create a new one, it will have same parameters to the highlighted one. Is there a way to make it behave same from command line? What am I missing? It always creates layer with default value [continuous, white...].
Any idea? Nothing fancy, it is for the macro side of a ToolPalette even Diesel if it can cope!
Thanx
Title: Re: Layer vs -Layer issue
Post by: Lee Mac on April 14, 2010, 07:29:03 AM
I would avoid the command call altogether and would copy all the properties of a layer using VL or AutoLISP - it might be less prone to error that way  :-)
Title: Re: Layer vs -Layer issue
Post by: Lee Mac on April 14, 2010, 09:18:37 AM
Perhaps something like:

Code: [Select]
(defun CopyLayerProps (source dest / itemp layers)
  ;; Lee Mac  ~  14.04.10
 
  (defun itemp (coll item)
    (if (not (vl-catch-all-error-p
               (setq result (vl-catch-all-apply
                              (function vla-item) (list coll item)
                            )
               )
             )
         )
      result
    )
  )

  (if (setq source
        (itemp
          (setq layers (vla-get-Layers
                         (vla-get-ActiveDocument
                           (vlax-get-acad-object)
                         )
                       )
           )
          source
        )
      )                         
    (progn
      (setq dest (cond (  (itemp layers dest))
                       (  (vla-Add layers dest))
                 )
      )
      (and
        (mapcar
          (function
            (lambda ( property )
              (if (vlax-property-available-p source property)
                (vlax-put-property dest property
                  (vlax-get-property source property)
                  )
                )
              )
            )
          '(Color Description Freeze
            LayerOn Linetype Lineweight
            Lock Material Plottable ViewportDefault)
        )
      )
    )
  )
)


Code: [Select]
(CopyLayerProps "Old Layer" "New Layer")

New Layer will be created if non-existent
Title: Re: Layer vs -Layer issue
Post by: alanjt on April 14, 2010, 10:14:21 AM
Nothing fancy, it is for the macro side of a ToolPalette even Diesel if it can cope!
Perhaps something like:
.....

 :lmao:

I'm not picking on you Lee, I just thought it was funny.

Title: Re: Layer vs -Layer issue
Post by: Lee Mac on April 14, 2010, 10:18:06 AM
Yeah, I suppose it wasn't too concise...  :|
Title: Re: Layer vs -Layer issue
Post by: alanjt on April 14, 2010, 10:20:28 AM
Yeah, I suppose it wasn't too concise...  :|
As much as it could be.
Title: Re: Layer vs -Layer issue
Post by: Serge J. Gianolla on April 14, 2010, 06:13:34 PM
Thanks guys.
The idea of using command is for portability and maintainance! As a macro it is built in the ToolPalette that can be sent to our interstates or o'seas branches. No need to send a lisp/vlx file, with all issues that may crop along. But ultimately the question still remains! Why is the behaviour different if you go via dialogue instead of command? I am not used to that in AutoCAD.
Title: Re: Layer vs -Layer issue
Post by: alanjt on April 14, 2010, 07:15:58 PM
Thanks guys.
The idea of using command is for portability and maintainance! As a macro it is built in the ToolPalette that can be sent to our interstates or o'seas branches. No need to send a lisp/vlx file, with all issues that may crop along. But ultimately the question still remains! Why is the behaviour different if you go via dialogue instead of command? I am not used to that in AutoCAD.
-Layer just wasn't coded that way. At best, it could take on the properties of the current layer, but it obviously doesn't do that.

You have to understand, -Layer predates the Layer Manager GUI.
Title: Re: Layer vs -Layer issue
Post by: Serge J. Gianolla on April 14, 2010, 07:46:58 PM
Yeah, but all commands from prompt line predate dialogue box driven ones! Array is the same regardless the method one is using, this is done in order to help with routines that were created 1278 years ago  :lmao: so is Block making or PLOT [bar the number of plots]...
Title: Re: Layer vs -Layer issue
Post by: Kerry on April 14, 2010, 07:51:53 PM
< .. >

You have to understand, -Layer predates the Layer Manager GUI.

(http://www.theswamp.org/screens/index.php?dir=&file=Green_Tick.png)

also, -Layer was designed for people who know how to use a keyboard   :wink:
Title: Re: Layer vs -Layer issue
Post by: Kerry on April 14, 2010, 07:52:52 PM
< .. >  help with routines that were created 1278 years ago  :lmao:  ...

 :-D
Title: Re: Layer vs -Layer issue
Post by: alanjt on April 14, 2010, 09:10:31 PM
< .. >

You have to understand, -Layer predates the Layer Manager GUI.

(http://www.theswamp.org/screens/index.php?dir=&file=Green_Tick.png)

also, -Layer was designed for people who know how to use a keyboard   :wink:
The GUI Layer Manger was already around when I started, but as soon as I found -layer, I changed my pgp and never looked back. The only reason I ever open the GUI is to change layer color/linetype properties in the viewport.
Title: Re: Layer vs -Layer issue
Post by: Lee Mac on April 15, 2010, 06:34:12 AM
Surely the way to do it is to use LISP/VLX and avoid command calls - they are the main reason programs don't work in later versions.
Title: Re: Layer vs -Layer issue
Post by: alanjt on April 15, 2010, 08:28:31 AM
Surely the way to do it is to use LISP/VLX and avoid command calls - they are the main reason programs don't work in later versions.
Not if it needs to be accomplished with macros, placed within a button or ToolPalette palette.

Just for the record, I have an old set of layer commands (all written with use of command calls) that were written back in 93 that were given to me by an engineer I used to work for. I used them until I learned how to write my own and I know he's still using them to this day.
Title: Re: Layer vs -Layer issue
Post by: curmudgeon on April 15, 2010, 01:50:45 PM
This is embarrassing. I have known most of what I need and forgotten. I would like to write for myself a simplified version of lman, just to switch between half a dozen preset layer states. I have used pull down menus, and I guess that was scripts. But I would like to do it with lisp.

I am slowly coming around to really liking vl-sort, but other than that, if it starts with "vl" I have not needed it - yet.

I can handle the symbol tables well enough, but the LAYERS table is not editable, in the same fashion as others. But it seems I remember a there is a way, or was, to simply freeze & thaw from pure lisp, and that is what I am after.

thanks

roy
Title: Re: Layer vs -Layer issue
Post by: Lee Mac on April 15, 2010, 01:56:39 PM
Check this out Roy  :-)

http://autodesk.com/techpubs/autocad/acad2000/dxf/layer_dxf_04.htm (http://autodesk.com/techpubs/autocad/acad2000/dxf/layer_dxf_04.htm)