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