Hi All,
Everybody can help me fix this error. When i clicked to 1 polyline my programing will draw 1 text ("a") into center this polyline. But when i tried change ucs so my text don't draw in center polyline. Although i have used TransformBy(). Thanks everybody.
<CommandMethod("AddRegion")> Public Sub Addr() '' Get the current document and database Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim acCurDb As Database = acDoc.Database Dim ed As Editor = acDoc.Editor Dim ucs As Matrix3d = ed.CurrentUserCoordinateSystem.Inverse() Dim peo As New PromptEntityOptions(vbLf & "Select a polyline : ") peo.SetRejectMessage(vbLf & "You have to select polyline only!") peo.AddAllowedClass(GetType(Polyline), False) Dim res As PromptEntityResult = ed.GetEntity(peo) If res.Status <> PromptStatus.OK Then Return End If '' Start a transaction Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction() Dim origin As Point2d = Point2d.Origin Dim poly As Polyline = DirectCast(acTrans.GetObject(res.ObjectId, OpenMode.ForRead), Polyline) '' Open the Block table for read Dim acBlkTbl As BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) '' Open the Block table record Model space for write Dim acBlkTblRec As BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _ OpenMode.ForWrite) '' Adds the circle to an object array Dim acDBObjColl As DBObjectCollection = New DBObjectCollection() acDBObjColl.Add(poly) '' Calculate the regions based on each closed loop Dim myRegionColl As DBObjectCollection = New DBObjectCollection() myRegionColl = Region.CreateFromCurves(acDBObjColl) Dim acRegion As Region = myRegionColl(0) '' Dim Solid As New Solid3d() Solid.Extrude(acRegion, 1, 0) Dim centroid As New Point2d(Solid.MassProperties.Centroid.X, Solid.MassProperties.Centroid.Y) Dim dtext As New DBText dtext.Position = New Point3d(centroid.X, centroid.Y, 0).TransformBy(ucs) dtext.TextString = "a" dtext.Height = 125 '' Add the new object to the block table record and the transaction acBlkTblRec.AppendEntity(dtext) acTrans.AddNewlyCreatedDBObject(dtext, True) '' Dispose of the in memory object not appended to the database '' Save the new object to the database acTrans.Commit() End Using End Sub
Hi,
I tried your code and saw the text "a" will be added to center of the selected polyline because of the code:
dtext.Position = New Point3d(centroid.X, centroid.Y, 0).TransformBy(ucs)
centroid is a solid centroid, solid was created from region, and region was from polyline. Therefore, you use the solid is a temp object to find the center point of a closed polyline.
I still don't understand the reason you use a UCS and transform the text with that UCS. Could you please explain more. However, I see your code works with your purpose.
-Khoa