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

Set current textstyle

5 REPLIES 5
Reply
Message 1 of 6
dheselwood
3760 Views, 5 Replies

Set current textstyle

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.
5 REPLIES 5
Message 2 of 6
Mep09Developer
in reply to: dheselwood

TEXTSTYLE system variable.
Message 3 of 6
dheselwood
in reply to: dheselwood

that will do it. Ok how would I set the dimstyle then because the dimstyle sysVar is readonly?
Message 4 of 6
Mep09Developer
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.
Message 5 of 6
dmcknight
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.
Message 6 of 6
Irvin
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

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