Jump to content

apply vba to subentities of block


Recommended Posts

Posted

i have a vba macro which used to apply bylayer color to the bylayer colored objects

but it didn't apply for blocks sub entities

i wish some one can modify the vba code to be applied to blocks and nested blocks

 

 

Public Sub ColorToEntity()
   'This subroutine sets each entities color from ByLayer
   'to the color of the layer it's on.
   Dim sset As AcadSelectionSet
   Set sset = ThisDrawing.SelectionSets.Add("SS1")

   ' Prompt the user to select objects
   ' and add them to the selection set.
   sset.SelectOnScreen

   
   ' Step through the selected objects and change
   ' each object's color to Green
   Dim objEntity As AcadEntity
   Dim objMS As AcadModelSpace
   Dim objPS As AcadPaperSpace
   Dim objLayers As AcadLayers
   Dim objLayer As AcadLayer
   Dim strLayer As String
   
   Set objMS = ThisDrawing.ModelSpace
   Set objPS = ThisDrawing.PaperSpace
   Set objLayers = ThisDrawing.Layers
   'process ents in modelspace
   For Each objEntity In objMS
       strLayer = objEntity.Layer
       Set objLayer = objLayers.Item(strLayer)
       objEntity.color = objLayer.color
   Next objEntity
   'process ents in paperspace
   For Each objEntity In objPS
       strLayer = objEntity.Layer
       Set objLayer = objLayers.Item(strLayer)
       objEntity.color = objLayer.color
   Next objEntity
   ' Remove the selection set at the end
   sset.Delete
End Sub

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