muck Posted May 6, 2009 Share Posted May 6, 2009 AutoCAD 2004-10. How does some get access to text in a block reference in order to change layer name or color in VBA? How does some get access to text in a block defination in order to change layer name or color in VBA? Do you need to go thur the block collection to get access? Does anyone have a sample code? Thank you, Quote Link to comment Share on other sites More sharing options...
BIGAL Posted May 6, 2009 Share Posted May 6, 2009 Do you only want to change one block or multiple of the same if the latter then just redefine block. Heres a start the block called "pitsched" is in the drawing multiple times the first attribute (0) is always unique in our case but ok if repeated the existing colour is attribs(2).color you can add the code to add colours and block name etc just remember attribs start at 0 Attrib(0) not 1 Dim SS As AcadSelectionSet Dim objENT As AcadEntity Dim Count, Cntr As Integer Dim Newpitname As String Dim pitname As String Dim FilterDXFCode(0) As Integer Dim FilterDXFVal(0) As Variant Dim PitNameSelect As AcadObject Dim basepnt, pt1, pt2, pt3 As Variant Dim attribs As Variant 'On Error Resume Next BLOCK_NAME = "SCHEDTEXT" pitname = "1A" FilterDXFCode(0) = 0 FilterDXFVal(0) = "INSERT" 'FilterDXFCode(1) = 2 'FilterDXFVal(1) = "SCHEDTEXT" Set SS = ThisDrawing.SelectionSets.Add("pit31sel") SS.Select acSelectionSetAll, , , FilterDXFCode, FilterDXFVal For Cntr = 0 To SS.Count - 1 If SS.Item(Cntr).Name = BLOCK_NAME Then attribs = SS.Item(Cntr).GetAttributes If attribs(0).TextString = pitname Then attribs(1).TextString = txtx1 attribs(2).TextString = TXTY1 colour = attribs(2).color MsgBox "attrib colour is " & colour attribs(2).color = 4 attribs(1).Update attribs(2).Update ' ThisDrawing.Application.Update Cntr = SS.Count Else: End If Else: End If Next Cntr ThisDrawing.SelectionSets.Item("pit1sel").Delete End Sub Checked it worked Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.