Hi Guys,
I try to place a block on top of another one, and make the new placed block the same same size as the other one. But the block scalefactors doesn't change.
Public Function FixtureConditionOverLayTest(objID as objectID) As Boolean Dim db As Database = acApp.DocumentManager.MdiActiveDocument.Database Dim trans As Transaction = acApp.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction Try '--Get Block Ref Dim objBRef As BlockReference = DirectCast(trans.GetObject(objID, OpenMode.ForRead), BlockReference) '--Check whether the blcok is exist Dim objBT As BlockTable = db.BlockTableId.GetObject(OpenMode.ForWrite) '--Insert 5dPlano Dim myNewBTR As BlockTableRecord = trans.GetObject(objBT(BlockTableRecord.ModelSpace), OpenMode.ForWrite) Dim objMyBlock As BlockReference = New BlockReference(objBRef.Position, objBT("5dPlano")) '--5dPlano is an existing block in drawing Testing.dwg Dim objScale As Scale3d = GetFixtureBlockScale(objBRef) '--Here I can see scale changed objMyBlock.ScaleFactors = objScale '--scale is still the same (1,1,0) objMyBlock.Color = Autodesk.AutoCAD.Colors.Color.FromColor(Color.Red) objMyBlock.Rotation = objBRef.Rotation objMyBlock.Layer = "5dFixture" myNewBTR.AppendEntity(objMyBlock) trans.AddNewlyCreatedDBObject(objMyBlock, True) trans.Commit() Catch ex As Exception Debug.Print(ex.Message) trans.Abort() Catch ex As System.Exception Debug.Assert(False) Debug.Print(ex.Message) trans.Abort() End Try End Function Private Function GetFixtureBlockScale(ByVal objBRef As BlockReference) As Scale3d Dim objExt As Extents3d = objBRef.Bounds Dim dblX As Double = objExt.MaxPoint.X - objExt.MinPoint.X Dim dblY As Double = objExt.MaxPoint.Y - objExt.MinPoint.Y Dim objScale As New Scale3d(dblX, dblY, 0) Return objScale End Function
But I use the same block "5dPlano" through COM, it works fine
Set objBlockRef = g_objDrawing.ModelSpace.InsertBlock(InsertionPoint:=varPoint, _ Name:=BlockName, _ xscale:=IIf(BlockName = STR_BLOCK_PLANO, dblLength, 1), _ yscale:=IIf(BlockName = STR_BLOCK_PLANO, dblDepth, 1), _ zscale:=1, _ Rotation:=Rotation)
How come the .Net method doesn't work?
Help!!!!!!!!!!!!!!!
Thanks
Solved! Go to Solution.
Solved by yaqiz. Go to Solution.
Is the block annotative? If it is, you need to add the annotation scales in .NET to match the existing block.
-Mark P.
i don't know how to add on
I tried to put this
objMyBlock.Annotative = AnnotativeStates.True
they error throw for einvalidinput.
The thing is after I inserted the new block I can change scale from perpertiy form.
Any help ?
Thanks
Yaqi
You can add annotative states like this:
Dim ocm As ObjectContextManager = db.ObjectContextManager Dim occ As ObjectContextCollection = ocm.GetContextCollection("ACDB_ANNOTATIONSCALES") blockRef.AddContext(occ.GetContext(db.Cannoscale.Name))
-Mark P.
So I'm pretty sure the reason your block isn't the same scale is because you are calculating the scale factor off of the extents of the block. The block could have a scale factor of (1,1,0) but could have an extents of (500,500,0) depending on the size of the geometry in the block definition.
instead of
objScale = GetFixtureBlockScale(objRef)
objMyBlock.ScaleFactors = objScale
you should probably just use
objMyBlock.ScaleFactors = objRef.ScaleFactors
-Mark P.
Hi Mark,
I have fixed the problem.
The key bit is
Dim scale As Scale3d = New Scale3d(48, 12, 1) '--None of the scale can be 0 bref.ScaleFactors = scale
In my previous code Zscale =0, it doesn't work and doesn't throw any exception either.
I found there are other post for the same reason, hope this can help