style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<dbartlett> wrote in messageHi
href="news:6072983@discussion.autodesk.com">news:6072983@discussion.autodesk.com...
All, I have a problem with using .Net to insert a dynamic block and set the
size property. The atrtribute text does not move correctly on insert, but will
if manually stretched after the fact. From my research the recommendation is
to make sure the attribute definition is marked as "Locked". However this has
not solved my problem. I have an attribute definition inside a circle (classic
door/window number), both the circle and attribute are included in the Action
Selection Set, however only the circle moves correctly. It all works correctly
if manually inserted/stretched. Any sage advice very much appreciated.
Regards, Dale
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<dbartlett> wrote in messageHi
href="news:6073004@discussion.autodesk.com">news:6073004@discussion.autodesk.com...
Tony, I'm open to any and all comments... Thanks, Dale 'insert block either
dynamic or not lstrBlockName = "Test" 'create block definition If
bt.Has(lstrBlockName) = True Then btrDrawobjectBlock =
ta.GetObject(bt.Item(lstrBlockName), OpenMode.ForRead) id =
btrDrawobjectBlock.Id Else dbDwg = New Database
dbDwg.ReadDwgFile(gstrFolderBlocks & "/" & lstrBlockName & ".dwg",
IO.FileShare.Read, True, "") id = db.Insert(lstrBlockName, dbDwg, False) End
If lblkDrawObject = New BlockReference(lpntInsertPoint, id) If
lblkDrawObject.IsDynamicBlock = False Then 'MsgBox(lstrBlockName & " is
not a dynamic block") 'set scale factor - not used in dynamic block
lblkDrawObject.ScaleFactors = lsclScaleFactor End If 'set rotation
lblkDrawObject.Rotation = 0 'add entity
btrShedBlock.AppendEntity(lblkDrawObject) 'tell transaction
ta.AddNewlyCreatedDBObject(lblkDrawObject, True) 'Get the dynamic block ref's
properties (params) If lblkDrawObject.IsDynamicBlock = True Then
dynBlkRefProps = lblkDrawObject.DynamicBlockReferencePropertyCollection For
Each dynBlkRefProp In dynBlkRefProps 'Set width and height Select Case
UCase(dynBlkRefProp.PropertyName) Case UCase("Width") dynBlkRefProp.Value =
ldblPropertyWidthValue Case UCase("Height") dynBlkRefProp.Value =
ldblPropertyHeightValue Case UCase("DoorSwingLeft") dynBlkRefProp.Value =
lshtPropertySwingValue Case UCase("RollerDoorOnOff") dynBlkRefProp.Value =
lstrPropertyRollerDoorValue Case Else 'MsgBox(dynBlkRefProp.PropertyName) End
Select Next End If 'modify the attribute of the block reference 'this will
ignore blocks without attributes btAttRec = ta.GetObject(id, OpenMode.ForRead)
For Each idAtt In btAttRec Dim ent As Entity ent = ta.GetObject(idAtt,
OpenMode.ForRead) If TypeOf ent Is AttributeDefinition Then Dim attDef As
AttributeDefinition attDef = CType(ent, AttributeDefinition) Dim attRef As New
AttributeReference() attRef.SetAttributeFromBlock(attDef,
lblkDrawObject.BlockTransform) 'attRef.Position = ptBase 'set attributes to
always horizontal, allowing for shed rotation attRef.Rotation = 0 'attRef.Tag
= attDef.Tag Select Case UCase(attDef.Tag) Case UCase("DOORNUM"),
UCase("WINNUM") attRef.TextString = lcDrawObject.DoorWinNumber End Select
'attRef.Height = attDef.Height 'attRef.FieldLength = attDef.FieldLength Dim
idTmp As ObjectId idTmp =
lblkDrawObject.AttributeCollection.AppendAttribute(attRef)
ta.AddNewlyCreatedDBObject(attRef, True) End If Next
Shared Sub ApplyAttributeDef(ByRef BlockReference As Autodesk.AutoCAD.DatabaseServices.BlockReference)
Dim Block As BlockTableRecord = BlockReference.BlockTableRecord.GetObject(Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)
If Not Block.HasAttributeDefinitions Then Exit Sub
If Block.Database Is Nothing Then Exit Sub
Dim Trans As Transaction = Block.Database.TransactionManager.StartTransaction
Try
If BlockReference.Database Is Nothing Then Block.Database.AddDBObject(BlockReference)
For Each Id As ObjectId In Block
Dim Ent As Entity = Id.GetObject(Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)
If TypeOf Ent Is AttributeDefinition Then
Dim AttDef As AttributeDefinition = Ent
Dim AttRef As New AttributeReference
BlockReference.AttributeCollection.AppendAttribute(AttRef)
AttRef.SetPropertiesFrom(AttDef)
AttRef.SetAttributeFromBlock(AttDef, BlockReference.BlockTransform)
Trans.AddNewlyCreatedDBObject(AttRef, True)
End If
Next
Trans.Commit()
Catch ex As Autodesk.AutoCAD.Runtime.Exception
Trans.Abort()
Finally
Trans.Dispose()
End Try
End Sub
BlockReference.AttributeCollection.AppendAttribute(AttRef)
AttRef.SetPropertiesFrom(AttDef)
AttRef.SetAttributeFromBlock(AttDef, BlockReference.BlockTransform)
if (attRef.IsMTextAttribute) attRef.UpdateMTextAttribute();
Hello dbarlett
Hi,
Not tested here, but may be a call to
blkRef.RecordGraphicsModified(True)
before the call to Transaction.AddNewlyCreatedBOject , may help to update the block instance.
Gaston Nunez
Can you post the block?, may be it's something related to the way it was created.
Gaston Nunez
Gaston, Thanks again.
Here is my code to move block to 0,0,0
and I submit the block as well. Thanks again
<CommandMethod("rrr")> _ Public Shared Sub vns_Get_And_Bring_TaperedRangeBlock1() Dim myobjid As ObjectId = vns_Select_one_object_on_Screen("select one screen") Dim Myobjidcol As New ObjectIdCollection Myobjidcol.Add(myobjid) vns_shift_Multi_Range_Line_block_postion_to_initial_origin(Myobjidcol, New Point3d(0, 0, 0)) End Sub Public Shared Sub vns_shift_Multi_Range_Line_block_postion_to_initial_origin(ByVal myobjidcol As ObjectIdCollection, ByVal BlockInsrPnt As Point3d) Dim mydwg As Document = Application.DocumentManager.MdiActiveDocument Dim MYed As Editor = mydwg.Editor Dim myDB As Database = mydwg.Database Using Tr As Transaction = myDB.TransactionManager.StartTransaction() Try Dim myBr As BlockReference For Each MyObjIditm In myobjidcol myBr = CType(Tr.GetObject(MyObjIditm, OpenMode.ForWrite), BlockReference) myBr.Position = BlockInsrPnt Next Tr.Commit() Catch ex As System.Exception End Try End Using End Sub
Hi,
If you just need to move the block reference, the best aproach is to use a 3D transform like this inside a transaction:
Dim DestPoint As New Point3d
Dim blkRef As BlockReference = promptR.ObjectId.GetObject(OpenMode.ForWrite)
Dim p As Point3d = blkRef.Position
Dim m3D AsNew Matrix3d
m3D = Matrix3d.Displacement(p.GetVectorTo(DestPoint))
blkRef.TransformBy(m3D)
MyTransaction.Commit
Gaston Nunez
Gaston ,
That was the trick . Good job sir. I need to learn these things. With a small brain it is hard to learn these things.
Thanks again Gaston.
Hope one Day I can make it up to you.
Regards,
Janet.