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

DBText AlignmentPoint does not work

5 REPLIES 5
Reply
Message 1 of 6
charliecheng
2846 Views, 5 Replies

DBText AlignmentPoint does not work

Hi! All:
I am adding a DBtext to a layout, the DBtext. alignmentPoint does not work, if I used it , no text will be drawn. But the DBText.position works, however, the text will not aligment to center. Any idea how to alignment text in net ?

Thank you very much

CLC


Dim pBT As Autodesk.AutoCAD.DatabaseServices.BlockTable
Dim pDWG As Autodesk.AutoCAD.ApplicationServices.Document
Dim pTransMan As Autodesk.AutoCAD.DatabaseServices.TransactionManager
Dim pTrans As Autodesk.AutoCAD.DatabaseServices.Transaction
Dim pEd As Autodesk.AutoCAD.EditorInput.Editor
Dim pDB As Autodesk.AutoCAD.DatabaseServices.Database
Dim pBTR As Autodesk.AutoCAD.DatabaseServices.BlockTableRecord
Dim pTST As Autodesk.AutoCAD.DatabaseServices.TextStyleTable
Dim pTSTR As Autodesk.AutoCAD.DatabaseServices.TextStyleTableRecord


pDWG = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

pDB = pDWG.Database
pEd = pDWG.Editor

pTransMan = pDWG.TransactionManager
pTrans = pTransMan.StartTransaction

pDWG.LockDocument()

pBT = pDWG.Database.BlockTableId.GetObject(OpenMode.ForRead)
pBTR = pBT(m_LayoutBTRName).GetObject(OpenMode.ForWrite)
pTST = pDB.TextStyleTableId.GetObject(OpenMode.ForRead)
pTSTR = pTST(m_ClsSheet.Band.Text.TextStyleName).GetObject(OpenMode.ForRead)

'Draw text
Dim pText As New Autodesk.AutoCAD.DatabaseServices.DBText
pText.TextString = sField.Desc
pText.Layer = m_ClsSheet.Band.Text.TextLayer
pText.TextStyle = pTSTR.ObjectId
pText.Height = m_ClsSheet.Band.SF * m_ClsSheet.Band.Text.TextHeight
pText.HorizontalMode = TextHorizontalMode.TextRight
pText.VerticalMode = TextVerticalMode.TextVerticalMid
pText.Position = New Autodesk.AutoCAD.Geometry.Point3d(sField.XDist, sField.YDist, 0)
'pText.AlignmentPoint = New Autodesk.AutoCAD.Geometry.Point3d(sField.XDist, sField.YDist, 0)

pBTR.AppendEntity(pText)
pTrans.AddNewlyCreatedDBObject(pText, True)

'pEd.Regen()

pText.Dispose()
pTrans.Commit()
pTrans.Dispose()
pTransMan.Dispose()
5 REPLIES 5
Message 2 of 6
Luizoo2008
in reply to: charliecheng

Hello guy, see te code above.
You must set the Horizontal and Vertical Mode first, so, You can set AlignMentPoint.

_
Sub DrawTextB()
Dim myTransMan As DatabaseServices.TransactionManager
Dim myTrans As DatabaseServices.Transaction
Dim myDWG As ApplicationServices.Document
Dim myBT As DatabaseServices.BlockTable
Dim myBTR As DatabaseServices.BlockTableRecord

myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument
myTransMan = myDWG.TransactionManager
myTrans = myTransMan.StartTransaction

myBT = myDWG.Database.BlockTableId.GetObject( _
DatabaseServices.OpenMode.ForRead)
myBTR = myBT(DatabaseServices.BlockTableRecord.ModelSpace).GetObject( _
DatabaseServices.OpenMode.ForWrite)

Dim myText As New DatabaseServices.DBText
myText.TextString = "testing"
myText.HorizontalMode = DatabaseServices.TextHorizontalMode.TextCenter
myText.VerticalMode = DatabaseServices.TextVerticalMode.TextVerticalMid
myText.AlignmentPoint = New Geometry.Point3d(2, 3, 0)

myBTR.AppendEntity(myText)
myTrans.AddNewlyCreatedDBObject(myText, True)

myTrans.Commit()
myTrans.Dispose()
myTransMan.Dispose()
End Sub
Message 3 of 6
charliecheng
in reply to: charliecheng

Thank you luizoo2008,
My problem is that if I add
pText.Position = New Autodesk.AutoCAD.Geometry.Point3d(sField.XDist, sField.YDist, 0)
, then the text will be drawn on paper space, but the text does not alignment to point. Otherwise no text will be drawn.

Dim pText As New Autodesk.AutoCAD.DatabaseServices.DBText
pText.TextString = sField.Desc
pText.HorizontalMode = Autodesk.AutoCAD.DatabaseServices.TextHorizontalMode.TextMid
pText.VerticalMode = Autodesk.AutoCAD.DatabaseServices.TextVerticalMode.TextVerticalMid
pText.AlignmentPoint = New Autodesk.AutoCAD.Geometry.Point3d(sField.XDist, sField.YDist, 0)
pText.Layer = m_ClsSheet.Band.Text.TextLayer
pText.TextStyle = pTSTR.ObjectId
pText.Height = m_ClsSheet.Band.SF * m_ClsSheet.Band.Text.TextHeight


pText.Position = New Autodesk.AutoCAD.Geometry.Point3d(sField.XDist, sField.YDist, 0)

pBTR.AppendEntity(pText)
pTrans.AddNewlyCreatedDBObject(pText, True)

Any idea?
Thank you in advance
Message 4 of 6
Luizoo2008
in reply to: charliecheng

Ok, my friend.

See the code above.
I was wrote then in C#.NET.

[CommandMethod("mytext")]
public void mytext ()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db1 = HostApplicationServices.WorkingDatabase;
Transaction trans = db1.TransactionManager.StartTransaction();
BlockTable bt1 = (BlockTable)trans.GetObject(db1.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr1 = (BlockTableRecord)trans.GetObject(bt1[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

DBText myTestText = new DBText();
myTestText.TextString = "Testando Alignment Text!...";
myTestText.HorizontalMode = TextHorizontalMode.TextCenter;
myTestText.VerticalMode = TextVerticalMode.TextVerticalMid;
myTestText.AlignmentPoint = new Point3d (100,100,0);

//If you use the Position Propierty now it will not work.
//(myTestText.Position = new Point3d(200, 200, 0);)

//If you want to change the position of text, you need to use Alignment Propierty
myTestText.AlignmentPoint = new Point3d(200, 200, 0);

//Then the problem is the Position Property. Understand me?

btr1.AppendEntity(myTestText);
trans.AddNewlyCreatedDBObject(myTestText,true);

trans.Commit();
trans.Dispose();
}

Then use the Alignment Property and not Position.

Cheers,

Luizoo
Message 5 of 6
charliecheng
in reply to: charliecheng

Thanks Luizoo !
Your code is working.
I found that the problem is that my text function is not in the class for [CommandMethod(..)] , after I moved the code to the class of [ComandMethod(..)], alignmentPoint works.
Thank you for your time again

Charlie
Message 6 of 6
Luizoo2008
in reply to: charliecheng

You are welcome Charlie

See you soon

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