.NET

Reply
Active Contributor
dheselwood
Posts: 35
Registered: ‎11-17-2003
Message 1 of 6 (1,557 Views)

Set current textstyle

1557 Views, 5 Replies
05-08-2009 05:02 AM
Ok having a dumb day, I can create my textstyle no problem, the issue im having is setting the textstyle current. There is a cLayer property for layers but how on earth do I do it with textstyles.

As always any help much appreciated.
Distinguished Contributor
Mep09Developer
Posts: 142
Registered: ‎11-03-2008
Message 2 of 6 (1,557 Views)

Re: Set current textstyle

05-08-2009 07:07 AM in reply to: dheselwood
TEXTSTYLE system variable.
Active Contributor
dheselwood
Posts: 35
Registered: ‎11-17-2003
Message 3 of 6 (1,557 Views)

Re: Set current textstyle

05-11-2009 03:59 AM in reply to: dheselwood
that will do it. Ok how would I set the dimstyle then because the dimstyle sysVar is readonly?
Distinguished Contributor
Mep09Developer
Posts: 142
Registered: ‎11-03-2008
Message 4 of 6 (1,557 Views)

Re: Set current textstyle

05-11-2009 10:09 AM in reply to: dheselwood
If you're going the ActiveX / COM route, use (document).ActiveDimStyle to set it.
Otherwise, if you're doing managed .NET, I'm not sure.
I haven't tried to tackle that with the managed API yet.
But, if I come across the solution, I'll post it.
Member
dmcknight
Posts: 4
Registered: ‎03-30-2009
Message 5 of 6 (1,557 Views)

Re: Set current textstyle

05-11-2009 11:09 AM in reply to: dheselwood
DimStyleTableRecord dsr = new DimStyleTableRecord();

trans.AddNewlyCreatedDBObject(dsr, true);
db.Dimstyle = dsr.ObjectId;


after your dimstyle is created (or if it already exists):
trans.AddNewlyCreatedDBObject(dsr, true);
then you can set the
db.Dimstyle = (the ObjectId of your newly created or existing dimstyle record from the DimStyleTableRecord.

I think that when you call db.Dimstyle = dsr.ObjectId; the settings for that dimstyle are set to the associated
system variables. Until I got the db.Dimstyle = dsr.ObjectId; part figured out, I noticed that I had the dimstyle
set but I always ended up using a "motified" version of the dimstyle.
Distinguished Contributor
Irvin
Posts: 112
Registered: ‎04-22-2009
Message 6 of 6 (1,557 Views)

Re: Set current textstyle

05-12-2009 05:27 AM in reply to: dheselwood
Here is a code snippet to achief your goal. It is for setting a dimstyle curent but it works te same for a text style. read the command at the end:



C# code




private void SetDimStyle(string dimStyleName)



{

Database db = HostApplicationServices.WorkingDatabase;

using (Transaction trans = db.TransactionManager.StartTransaction())

{

DimStyleTable DimTabb = (DimStyleTable)trans.GetObject(db.DimStyleTableId, OpenMode.ForRead);

if (DimTabb.Has(dimStyleName))

{

DimStyleTableRecord DimTabbRecaord = (DimStyleTableRecord)trans.GetObject(DimTabb[dimStyleName], OpenMode.ForRead);

if (DimTabbRecaord.ObjectId != db.Dimstyle)



{

db.Dimstyle = DimTabbRecaord.ObjectId;

//A similar method might not be needed in the case of text style setting a similar property as above should be enough

db.SetDimstyleData(DimTabbRecaord);



}



}



}



}







VB.NET Code



Private Sub SetDimStyle(ByVal dimStyleName As String)



Dim db As Database = HostApplicationServices.WorkingDatabase



Using trans As Transaction = db.TransactionManager.StartTransaction()



Dim DimTabb As DimStyleTable = DirectCast(trans.GetObject(db.DimStyleTableId, OpenMode.ForRead), DimStyleTable)



If DimTabb.Has(dimStyleName) Then



Dim DimTabbRecaord As DimStyleTableRecord = DirectCast(trans.GetObject(DimTabb(dimStyleName), OpenMode.ForRead), DimStyleTableRecord)

if DimTabbRecaord.ObjectId <> db.Dimstyle Then



db.Dimstyle = DimTabbRecaord.ObjectId



'A similar method might not be needed in the case of text style setting a similar property as above should be enough



db.SetDimstyleData(DimTabbRecaord)



End If



End If



End Using

End Sub




Hope this snippet helps you to solve your problem. Edited by: Irvin on May 12, 2009 1:25 PM
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.