bababarghi Posted May 14, 2013 Posted May 14, 2013 Hi all, I have got this code by KEAN WALMSLEY. His code will ask user to select a block and then list all of selected block's attributes. However, I need to tweak his code a little bit and instead of user interaction, the block has to be selected by its name and through my code. Here is his code (with slight changes to suit my purpose): Private Sub ListAttributes() Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor Dim db As Database = HostApplicationServices.WorkingDatabase Dim tr As Transaction = db.TransactionManager.StartTransaction() Try Dim filList As TypedValue() = New TypedValue(0) {New TypedValue(CInt(DxfCode.Start), "INSERT")} Dim filter As New SelectionFilter(filList) Dim opts As New PromptSelectionOptions() opts.MessageForAdding = "Select block references: " Dim res As PromptSelectionResult = ed.GetSelection(opts, filter) If res.Status <> PromptStatus.OK Then Return End If Dim selSet As SelectionSet = res.Value Dim idArray As ObjectId() = selSet.GetObjectIds() For Each blkId As ObjectId In idArray Dim blkRef As BlockReference = DirectCast(tr.GetObject(blkId, OpenMode.ForRead), BlockReference) Dim btr As BlockTableRecord = DirectCast(tr.GetObject(blkRef.BlockTableRecord, OpenMode.ForRead), BlockTableRecord) ed.WriteMessage(vbLf & "Block: " + btr.Name) btr.Dispose() Dim attCol As AttributeCollection = blkRef.AttributeCollection For Each attId As ObjectId In attCol Dim attRef As AttributeReference = DirectCast(tr.GetObject(attId, OpenMode.ForRead), AttributeReference) Dim str As String = (vbLf & attRef.Tag + " " & attRef.TextString) ed.WriteMessage(str) Next Next tr.Commit() Catch ex As Autodesk.AutoCAD.Runtime.Exception ed.WriteMessage(("Exception: " + ex.Message)) Finally tr.Dispose() End Try End Sub Now, I need to change this Sub to a Function as below: Private Function ListAttributes (blockName As String) As Boolean The goal is to list all block attributes if the 'blockName' exists in drawing and return True afterwards. Oppositely it should return me False and print nothing to Editor if blockName does not exist. Can anyone help me please? Cheers Quote
fixo Posted May 15, 2013 Posted May 15, 2013 Please, stop double posting I've answered on Discussion groups Quote
bababarghi Posted May 15, 2013 Author Posted May 15, 2013 My apology. Didn't know that pro users monitor couple of CAD forums simultaneously , Thanks anyway. Quote
fixo Posted May 15, 2013 Posted May 15, 2013 No problem, it's just a common rule for Acad forums Cheers Quote
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.