Jump to content

Macro?


pvd

Recommended Posts

Hi all,

 

I'm looking for somethiing that puts colour, linetype and lineweight of an object by layer. Is there a macro for this? Who could help me with it as I know nothing about Visual Basic.

 

Thank you very much

Link to comment
Share on other sites

VLISP:

 

(defun c:test (/ i obj ss)
 (vl-load-com)
 (setq i -1 *doc (cond (*doc) ((vla-get-ActiveDocument (vlax-get-acad-object)))))
 
 (cond ((ssget "_:L")
        (vlax-for obj (setq ss (vla-get-ActiveSelectionSet *doc))
          (mapcar
            (function (lambda (prop value) (vlax-put-property obj prop value)))
            '(Color Linetype Lineweight) (list acByLayer "ByLayer" acLnWtByLayer)))
        (vla-delete ss)))

 (princ))

Link to comment
Share on other sites

My VBA is pretty bad but:

 

Sub 2ByLayer ( )

 Dim sSet As AcadSelectionSet
 Set sSet = ThisDrawing.SelectionSets.Add("ByLayerSet")

 sSet.SelectOnScreen

 For i = 0 To sSet.Count

   sSet.Item(i).Linetype = "BYLAYER"
   sSet.Color = acByLayer
   sSet.Lineweight = acLnWtByLayer

 Next i

 sSet.Delete

End Sub

 

Suggestions are appreciated for the VBA...

Link to comment
Share on other sites

Thanks a lot Lee!

Now excuse my stupidity but I can't get the script working. I pasted the code in my Visual LISP Editor, right? And then I do what?

 

Thanks again

Link to comment
Share on other sites

Suggestions are appreciated for the VBA...

I had to do this......

Public Sub AByLayer()
Dim i as Integer
 Dim sSet As AcadSelectionSet
 Set sSet = ThisDrawing.SelectionSets.Add("ByLayerSet")
 sSet.SelectOnScreen
 For i = 0 To sSet.Count - 1
   sSet.Item(i).Linetype = "ByLayer"
   sSet.Item(i).color = acByLayer
   sSet.Item(i).Lineweight = acLnWtByLayer
 Next i
 sSet.Delete
End Sub

I had to start the procedure name with a letter, not a number.

My setup requires variables to be declared so I added the Dim statement.

Take one off the "count".

add .Item(i) to the color & lineweight lines.

Link to comment
Share on other sites

Wow - can't believe I missed those "Item(i)" statements! That was sloppy.

 

Thanks for that Dave - You see, I don't have VBA installed on my CAD, and haven't had a chance to get it yet, so all my VBA code is just 'theoretical', helped by examples.

 

Lee

Link to comment
Share on other sites

you did better than I do and I have VBA installed! :)

 

Well - I don't know - you have been VBA'ing a lot longer than I have :)

 

OK, so just to clarify:

 

  • Does the "Public Sub" mean that the function can be invoked at the command line? Whereas just "Sub" meaning it is a Sub-function?

  • Symbols used in For loops need to be declared also.

  • Numbers cannot be used in Function names.

Thanks Dave for this - appreciated.

 

Lee

Link to comment
Share on other sites

that may be so but the last formal training I had was on FORTRAN (in about 1977), the rest I have picked up as I have gone along.

 

Public - not sure, I don't normally use it and it works just as well without. The help file says....

 

PublicOptional. Indicates that the Sub procedure is accessible to all other procedures in all modules. If used in a module that contains an Option Private statement, the procedure is not available outside the project.

 

symbols do not need to be declared but I have "Option Explicit" set so you do. This is under Tools|Options|Require variable declaration. I prefer to have this set as I have a habit of mistyping variables and I wonder why I get odd results.

 

Naming - I can't actually find anything to support the first char must be a letter but I can't get it to run if it doesn't.

 

Hopefully somebody who isn't self taught (or at least studied harder) will be along soon to put us right.

Link to comment
Share on other sites

that may be so but the last formal training I had was on FORTRAN (in about 1977), the rest I have picked up as I have gone along.

 

Public - not sure, I don't normally use it and it works just as well without. The help file says....

 

 

 

symbols do not need to be declared but I have "Option Explicit" set so you do. This is under Tools|Options|Require variable declaration. I prefer to have this set as I have a habit of mistyping variables and I wonder why I get odd results.

 

Naming - I can't actually find anything to support the first char must be a letter but I can't get it to run if it doesn't.

 

Hopefully somebody who isn't self taught (or at least studied harder) will be along soon to put us right.

 

Thanks Dave - it all helps fill the gaps in my knowledge :)

Link to comment
Share on other sites

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