Jump to content

Recommended Posts

Posted
Thank you! :)

 

 

 

Thank you for your compliments, though the use of a reactor in this program is actually relatively simple - if you were looking for more advanced examples to study, you may want to consider my Associative Textbox program or Automatically Label Attributes program.

Those are really cool programs, thanks for the reference! Also, I had a quick question. For the plot style, I am entering in "Black" into the plot style and yet, it is still creating the layer as a normal plot style. Do you know why that could be?
  • Replies 45
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    19

  • ksperopoulos

    17

  • broncos15

    7

  • BlackBox

    3

Posted
For the plot style, I am entering in "Black" into the plot style and yet, it is still creating the layer as a normal plot style. Do you know why that could be?

 

I'll investigate - I've always used CTB drawings and so unfortunately I don't have much experience with Named Plot Styles, but it may be that the Plot Style is not added to the acad_plotstylename dictionary until at least one layer references it.

Posted

Lee - I have tried to study your code, but it seems to reference a 'lambda' function. Is that correct? If so, my brain shuts off when it comes to 'lambda'. For the life of me, I can't seem to understand it.

 

On the other hand, I have tried to take the visual lisp route. Since I am pretty green when it comes to this style, I could use some feedback. This is not working and I can't figure out why. Any guidance would be appreciated.

(defun c:createlayer ( laycoll layname layonoff layfrzthaw laylockunlock laycolor layltype laylweight layplot laydesc )
   (vl-load-com)
   (setq acadobj (vlax-get-acad-object)
             doc (vla-get-activedocument acadobj)
         laycoll (vla-get-layers doc)
         layname "G-ANNO-ELEV"
        layonoff :vlax-true
      layfrzthaw :vlax-false
   laylockunlock :vlax-false
        laycolor acWhite
        layltype "Continuous"
      laylweight acLnWt025
         layplot :vlax-true
         laydesc "Elevation Tags"
   )
   (if (null (tblsearch "LAYER" layname))
       (progn
           (vla-add laycoll layname)
           (vla-put-layeron layname layonoff)
           (vla-put-freeze layname layfrzthaw)
           (vla-put-lock layname laylockunlock)
           (vla-put-color layname laycolor)
           (vla-put-linetype layname layltype)
           (vla-put-lineweight layname laylweight)
           (vla-put-plottable layname layplot)
           (vla-put-description layname laydesc)
       )
   )
   (princ)
)

Posted

You need to modify the properties of the layer object returned by:

(vla-add laycoll layname)

The first argument supplied to vla-put-* is always a vla-object; you are currently supplying the layer name (a string).

 

You should assign the layer object to a local variable and then modify the properties of this object, i.e.:

(setq obj (vla-add laycoll layname))
(vla-put-layeron obj layonoff)
...

Posted

Thank you Lee. I took your advice and did what you said, but now I am getting an error that I have "too few arguments". I scanned my code and don't see what this error message is referring to. I don't know of anything that requires an argument. Do you?

Posted

You're welcome - looks like you're missing the variable declaration here:

c:createlayer ( [highlight]/[/highlight] laycoll layname

Posted

Thank you again Lee. I guess I need to look at all of the code instead of just what is below the name of the function.

Posted
You need to modify the properties of the layer object returned by:

(vla-add laycoll layname)

The first argument supplied to vla-put-* is always a vla-object; you are currently supplying the layer name (a string).

 

You should assign the layer object to a local variable and then modify the properties of this object, i.e.:

(setq obj (vla-add laycoll layname))
(vla-put-layeron obj layonoff)
...

 

Is there a different function that I could use instead of vla-add in the second part of the code below? Basically, what I am trying to say is - if the drawing file does not have the layer in it, then create the layer. If it does have the layer in the file, then set that layer's properties to on, thawed, unlocked. The vla-add function seems appropriate for the 'then expression' but not for the 'else expression'. Would vla-for be more appropriate?

 

        (if (null (tblsearch "LAYER" layname))
           (progn
               (setq layobj (vla-add laycoll layname))
               (vla-put-layeron layobj layon)
               (vla-put-freeze layobj layfrz)
               (vla-put-lock layobj laylock)
               (vla-put-color layobj laycolor)
               (vla-put-linetype layobj layltype)
               (vla-put-lineweight layobj laylwt)
               (vla-put-plottable layobj layplot)
               (vla-put-description layobj laydesc)
           )
           (progn
               (setq layobj (vla-add laycoll layname))
               (vla-put-layeron layobj layon)
               (vla-put-freeze layobj layfrz)
               (vla-put-lock layobj laylock)
           )
       )

Posted

Here are three possible ways to approach it:

(if (setq obj (tblobjname "layer" layname))
   (setq obj (vlax-ename->vla-object obj))
   (progn
       (setq obj (vla-add laycoll layname))
       (vla-put-color       obj laycolor)
       (vla-put-linetype    obj layltype)
       (vla-put-lineweight  obj laylwt)
       (vla-put-plottable   obj layplot)
       (vla-put-description obj laydesc)
   )
)
(vla-put-layeron obj layon)
(vla-put-freeze  obj layfrz)
(vla-put-lock    obj laylock)

(if (vl-catch-all-error-p (setq obj (vl-catch-all-apply 'vla-item (list laycoll layname))))
   (progn
       (setq obj (vla-add laycoll layname))
       (vla-put-color       obj laycolor)
       (vla-put-linetype    obj layltype)
       (vla-put-lineweight  obj laylwt)
       (vla-put-plottable   obj layplot)
       (vla-put-description obj laydesc)
   )
)
(vla-put-layeron obj layon)
(vla-put-freeze  obj layfrz)
(vla-put-lock    obj laylock)

(vlax-for lay laycoll
   (if (= layname (vla-get-name lay)) (setq obj lay))
)
(if (null obj)
   (progn
       (setq obj (vla-add laycoll layname))
       (vla-put-color       obj laycolor)
       (vla-put-linetype    obj layltype)
       (vla-put-lineweight  obj laylwt)
       (vla-put-plottable   obj layplot)
       (vla-put-description obj laydesc)
   )
)
(vla-put-layeron obj layon)
(vla-put-freeze  obj layfrz)
(vla-put-lock    obj laylock)

Posted

(vlax-for lay laycoll
   (if (= layname (vla-get-name lay)) (setq obj lay))
)
(if (null obj)
   (progn
       (setq obj (vla-add laycoll layname))
       (vla-put-color       obj laycolor)
       (vla-put-linetype    obj layltype)
       (vla-put-lineweight  obj laylwt)
       (vla-put-plottable   obj layplot)
       (vla-put-description obj laydesc)
   )
)
(vla-put-layeron obj layon)
(vla-put-freeze  obj layfrz)
(vla-put-lock    obj laylock)

 

Lee - Like I mentioned in my previous post, vlax-for is the path I was thinking about taking, but it seems like I should be able to get the name of the layer by using the vla-get-name function. Why is the name of the layer not accessible via this method? Is it because vlax-* functions work on a specific object and vla-* functions work on more than one object?

 

(Sorry for my ignorance. I am just trying to understand and I appreciate your patience.)

Posted
but it seems like I should be able to get the name of the layer by using the vla-get-name function. Why is the name of the layer not accessible via this method?

 

You can - vla-get-name will return the ActiveX Name property of a vla-object (just as any vla-get-X function returns the 'X' property of a vla-object); but note that the code is operating on the vla Layer object, not the layer name (which is merely a string).

 

You can retrieve the vla Layer object directly from the Layer Collection by its layer name using the vla-item function, as demonstrated by my second example above.

Posted

Thank you. I think I understand.:unsure:

Posted
See lines 324-336 of my Layer Director program for an existing example of how to set a layer description using Vanilla AutoLISP.

 

Lee - I've been trying to study the code you are referring to in your Layer Director program (despite my phobia of the lambda function). I'm curious why you used vl-list* instead of list? Is it because the plot style and layer description are appended?

Posted
I'm curious why you used vl-list* instead of list? Is it because the plot style and layer description are appended?

 

The vl-list* function is similar to the cons function in that the type of result that it returns is dependent on the data types of the supplied arguments.

 

If supplied with two atoms, or an atom and a list, vl-list* will perform in the same way as cons:

_$ (vl-list* 1 2)
(1 . 2)
_$ (cons 1 2)
(1 . 2)
_$ (vl-list* 1 '(2))
(1 2)
_$ (cons 1 '(2))
(1 2)

 

However, where cons only accepts two arguments, vl-list* may be supplied with multiple arguments which yields a behaviour similar to a set of nested cons expressions:

_$ (vl-list* 1 2 3 4 '(5))
(1 2 3 4 5)
_$ (cons 1 (cons 2 (cons 3 (cons 4 '(5)))))
(1 2 3 4 5)
_$ (vl-list* 1 2 3 4 5)
(1 2 3 4 . 5)
_$ (cons 1 (cons 2 (cons 3 (cons 4 5))))
(1 2 3 4 . 5)

Posted

So since you need to get the dotted pair within the two portions of your append function, you wouldn't have been able to do it another way? Or is this way just cleaner?

Posted
So since you need to get the dotted pair within the two portions of your append function, you wouldn't have been able to do it another way? Or is this way just cleaner?

 

There are of course other ways to achieve the same thing, but in my opinion this way is the cleanest.

 

I am essentially doing this:

_$ (vl-list* 1 2 3 4 5 '(6 7))
(1 2 3 4 5 6 7)

Which I could have equally achieved by doing either of these:

_$ (append (list 1 2 3 4 5) '(6 7))
(1 2 3 4 5 6 7)

_$ (cons 1 (cons 2 (cons 3 (cons 4 (cons 5 '(6 7))))))
(1 2 3 4 5 6 7)

Posted

Lee, I was thinking about your Layer Director LISP recently and a quick fix for the plot style in the program not working could be to use your Steal function. I know that I have used it a lot in my LISP programs, and it could probably reduce the overall size of your code.

Posted (edited)
There are of course other ways to achieve the same thing, but in my opinion this way is the cleanest.

 

I chose to do it a slightly different way than what you suggest. Since the list for the layer description won't change except for the second dotted 1000 pair, I chose to store that in a variable within the main function:

 

(setq layname "G-ANNO-ELEV"
        layltype "Continuous"
        laycolor 7
        laystate 0
          layplot 1
     laylweight 25
         laydesc '(-3 ("AcAecLayerStandard" (1000 . "") (1000 . "Elevation Tags")))
)

 

Then, within the subfunction I can use append to attach the layer description to the rest of the entmake list.

 

(entmake (list '(0 . "LAYER")
                    '(100 . "AcDbSymbolTableRecord")
                    '(100 . "AcDbLayerTableRecord")
                     (cons 2 layname)
                     (cons 6 layltype)
                     (cons 62 laycolor)
                     (cons 70 laystatus)
                     (cons 290 layplot)
                     (cons 370 laylwt)
                     (progn (regapp "AcAecLayerStandard")
                               (append laydesc)
                     )
              )
)

Edited by ksperopoulos
Posted

FWIW, the append expression is unnecessary in your case - you can also perform the regapp outside of the entmake expression to avoid the need for progn.

Posted

I don't understand why append is unnecessary. How is it going to be a part of the list?

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