.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Fields and excessive Xrecords in dynamic blocks

2 REPLIES 2
Reply
Message 1 of 3
MrRamsden
384 Views, 2 Replies

Fields and excessive Xrecords in dynamic blocks

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

 

 

2 REPLIES 2
Message 2 of 3
MrRamsden
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.

Message 3 of 3
cincir
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

 


Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost