.NET

.NET

Reply
Active Contributor
MrRamsden
Posts: 26
Registered: ‎08-29-2008
Message 1 of 3 (176 Views)

Fields and excessive Xrecords in dynamic blocks

176 Views, 2 Replies
01-11-2012 02:29 AM

Hi all

 

I've recently made the jump into .net development and I'm fairly happy with progress so far.

 

I've managed to make a custom jig that does pretty much everything I want it to do, but with a couple of issues:

 

  1. After entering the first click the block then starts generating xrecords and dbdictionaries (I'm using the Autodesk tutorial code that adds a palette that displays all drawing objects as they're added). I have no code that explicitly does this as I don't need xrecords at this stage. The code that appears to be generating them is below:

 

Case

1

                       

'if second click

                       

IfNot _scanned1 Then

                           

ForEach objItem AsDynamicBlockReferencePropertyIn block.DynamicBlockReferencePropertyCollection

                               

If objItem.PropertyName.ToString() = "length"AndNot _found1 Then

                                    _length = objItem

                                    _found1 =True

                               

ElseIf objItem.PropertyName.ToString() = "height"AndNot _found2 Then

                                    _height = objItem

                                    _found2 =True

                               

ElseIf _found1 And _found2 Then

                                    _scanned1 =True

                                   Exit For

EndIf

                           

Next

                            ed.WriteMessage("Parameters identified")

                       

EndIf

                        _length.Value = _pos2.X - _pos.X

                        _height.Value = _pos2.Y - _pos.Y

                       

If _length.Value < 0 Then

                            _length.Value = _length.Value * -1

EndIf

                       

If _height.Value < 0 Then

                            _height.Value = _height.Value * -1

EndIf

 

 

The problem with the creation of the xrecords and dbdictionaries is that it slows everything down. They seem to be created everytime you move the mouse...

 

2.     I'm struggling with fields. There is a field in an attribute of the block that reads the area from the only polyline that's in the block. I think the difficulty I'm having is iterating through the block to find the polyline and its objectid. Without the objectid I can't apply the field. Code is below:

 

If

blockTableRecord.HasAttributeDefinitions Then

                   

ForEach id AsObjectIdIn blockTableRecord

                       

Dim obj AsDBObject = trans.GetObject(id, OpenMode.ForRead)

                       

Dim attDef AsAttributeDefinition = TryCast(obj, AttributeDefinition)

                       

IfTypeOf obj IsPolylineThen

                            ed.WriteMessage("Polyline found")

                            objId = obj.ObjectId                       

EndIf

                       

If attDef IsNotNothingAndAlsoNot attDef.Constant Then

                           

Dim attRef AsAttributeReference = NewAttributeReference

                            attRef.SetAttributeFromBlock(attDef, block.BlockTransform)

                            attRef.Position = attDef.Position.TransformBy(block.BlockTransform)

                           

If attDef.Justify <> AttachmentPoint.BaseLeft Then

                                attRef.AlignmentPoint = attDef.AlignmentPoint.TransformBy(block.BlockTransform)                           

EndIf

                           

If attRef.IsMTextAttribute Then

                                attRef.UpdateMTextAttribute()                           

EndIf

                           

If attRef.Tag = "STANDAREA"Then

                               

'ed.WriteMessage(vbLf & "Attribute has a field")

                                attRef.TextString ="%<\AcObjProp Object(%<\_ObjId " + objId.ToString() + ">%).Area>%"

EndIf

'---------------------------etc

 

Apologies if these questions have been answered before, but I can't find anything that's specific to these issues.

 

Thanks

 

MrRamsden

 

 

Active Contributor
MrRamsden
Posts: 26
Registered: ‎08-29-2008
Message 2 of 3 (129 Views)

Re: Fields and excessive Xrecords in dynamic blocks

01-23-2012 09:37 AM in reply to: MrRamsden

For anyone who cares, I changed my jig to draw a rectangle which is used to size and position the block, so the heavy blockJig stuff doesn't happen.

 

I managed to cycle through the blockTableRecord of the block and find the polyline and the field now works perfectly. I think I managed to find an example of how to do it properly on here eventually, but if anyone wants it just ask.

Active Contributor
cincir
Posts: 32
Registered: ‎08-12-2011
Message 3 of 3 (123 Views)

Re: Fields and excessive Xrecords in dynamic blocks

01-23-2012 11:10 AM in reply to: MrRamsden

try this instead

 

If blockTableRecord.HasAttributeDefinitions Then
                   
ForEach id AsObjectIdIn blockTableRecord
                       
Dim obj AsDBObject = trans.GetObject(id, OpenMode.ForRead)
                       
Dim attDef AsAttributeDefinition = TryCast(obj, AttributeDefinition)
                       
IfTypeOf obj IsPolylineThen
                            ed.WriteMessage("Polyline found")
                            objId = obj.ObjectId                       

                       
If attDef IsNotNothingAndAlsoNot attDef.Constant Then
                           
Dim attRef AsAttributeReference = NewAttributeReference
                            attRef.SetAttributeFromBlock(attDef, block.BlockTransform)
                            attRef.Position = attDef.Position.TransformBy(block.BlockTransform)
                           
If attDef.Justify <> AttachmentPoint.BaseLeft Then
                                attRef.AlignmentPoint = attDef.AlignmentPoint.TransformBy(block.BlockTransform)                           
EndIf
                           
If attRef.IsMTextAttribute Then
                                attRef.UpdateMTextAttribute()                           
EndIf
                           
If attRef.Tag = "STANDAREA"Then
                               
'ed.WriteMessage(vbLf & "Attribute has a field")
                                attRef.TextString ="%<\AcObjProp Object(%<\_ObjId " + objId.ToString() + ">%).Area>%"
EndIf
 
EndIf

 


Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.