Jump to content
zetazee

Activate or Deactivate DisplayTheme in DWG using .NET API

Recommended Posts

zetazee

Hi,

 

I have 2 display themes in my DWG, and would like to use the .NET API to activate one display theme and deactivate the other.

 

I have searched AutoCAD forums and here, but there wasn't any threads on this.

 

Current findings so far. Showing part of my code.

DisplayTheme has the public data member IsActive, and I was able to access the 2 display themes in my DWG, whereby one is active, the other is not.

Search through the list of DisplayTheme public methods, but there was not any that could activate or deactivate it.

 

DisplayTheme dt = tm.GetObject(id, OpenMode.ForWrite) as DisplayTheme;

ed.WriteMessage(dt.IsActive + "\n");

 

Any assistance would be great. Thanks.

Share this post


Link to post
Share on other sites
Jeff H

I can not get it to attach.

 

[size=2]
[[/size][size=2][color=#010001][size=2][color=#010001]CommandMethod[/color][/size][/color][/size][size=2]([/size][size=2][color=#a31515][size=2][color=#a31515]"ChangeDisplayThemes"[/color][/size][/color][/size][size=2])]
[/size][size=2][color=#0000ff][size=2][color=#0000ff]public[/color][/size][/color][/size][size=2] [/size][size=2][color=#0000ff][size=2][color=#0000ff]void[/color][/size][/color][/size][size=2] [/size][size=2][color=#010001][size=2][color=#010001]ChangeDisplayThemes[/color][/size][/color][/size][size=2]()
{
[/size][size=2][color=#010001][size=2][color=#010001]Document[/color][/size][/color][/size][size=2] [/size][size=2][color=#010001][size=2][color=#010001]doc[/color][/size][/color][/size][size=2] = [/size][size=2][color=#010001][size=2][color=#010001]Application[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]DocumentManager[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]MdiActiveDocument[/color][/size][/color][/size][size=2];
[/size][size=2][color=#010001][size=2][color=#010001]Database[/color][/size][/color][/size][size=2] [/size][size=2][color=#010001][size=2][color=#010001]db[/color][/size][/color][/size][size=2] = [/size][size=2][color=#010001][size=2][color=#010001]doc[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]Database[/color][/size][/color][/size][size=2];
[/size][size=2][color=#010001][size=2][color=#010001]Editor[/color][/size][/color][/size][size=2] [/size][size=2][color=#010001][size=2][color=#010001]ed[/color][/size][/color][/size][size=2] = [/size][size=2][color=#010001][size=2][color=#010001]doc[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]Editor[/color][/size][/color][/size][size=2];
[/size][size=2][color=#0000ff][size=2][color=#0000ff]using[/color][/size][/color][/size][size=2] ([/size][size=2][color=#010001][size=2][color=#010001]Transaction[/color][/size][/color][/size][size=2] [/size][size=2][color=#010001][size=2][color=#010001]trx[/color][/size][/color][/size][size=2] = [/size][size=2][color=#010001][size=2][color=#010001]db[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]TransactionManager[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]StartTransaction[/color][/size][/color][/size][size=2]())
{

[/size][size=2][color=#010001][size=2][color=#010001]DisplayRepresentationManager[/color][/size][/color][/size][size=2] [/size][size=2][color=#010001][size=2][color=#010001]disRepMngr[/color][/size][/color][/size][size=2] = [/size][size=2][color=#0000ff][size=2][color=#0000ff]new[/color][/size][/color][/size][size=2] [/size][size=2][color=#010001][size=2][color=#010001]DisplayRepresentationManager[/color][/size][/color][/size][size=2]([/size][size=2][color=#010001][size=2][color=#010001]db[/color][/size][/color][/size][size=2]);
[/size][size=2][color=#010001][size=2][color=#010001]DisplayConfiguration[/color][/size][/color][/size][size=2] [/size][size=2][color=#010001][size=2][color=#010001]currentDisplayConfig[/color][/size][/color][/size][size=2] =
[/size][size=2][color=#010001][size=2][color=#010001]disRepMngr[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]DisplayConfigurationIdForCurrentViewport[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]GetObject[/color][/size][/color][/size][size=2]([/size][size=2][color=#010001][size=2][color=#010001]OpenMode[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]ForWrite[/color][/size][/color][/size][size=2]) [/size][size=2][color=#0000ff][size=2][color=#0000ff]as[/color][/size][/color][/size][size=2] [/size][size=2][color=#010001][size=2][color=#010001]DisplayConfiguration[/color][/size][/color][/size][size=2];
[/size][size=2][color=#010001][size=2][color=#010001]DictionaryDisplayThemeStyle[/color][/size][/color][/size][size=2] [/size][size=2][color=#010001][size=2][color=#010001]displayThemes[/color][/size][/color][/size][size=2] = [/size][size=2][color=#0000ff][size=2][color=#0000ff]new[/color][/size][/color][/size][size=2] [/size][size=2][color=#010001][size=2][color=#010001]DictionaryDisplayThemeStyle[/color][/size][/color][/size][size=2]([/size][size=2][color=#010001][size=2][color=#010001]db[/color][/size][/color][/size][size=2]);
[/size][size=2][color=#010001][size=2][color=#010001]ObjectId[/color][/size][/color][/size][size=2] [/size][size=2][color=#010001][size=2][color=#010001]displayThemeId[/color][/size][/color][/size][size=2] = [/size][size=2][color=#010001][size=2][color=#010001]displayThemes[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]GetAt[/color][/size][/color][/size][size=2]([/size][size=2][color=#a31515][size=2][color=#a31515]"Standard"[/color][/size][/color][/size][size=2]);
[/size][size=2][color=#0000ff][size=2][color=#0000ff]if[/color][/size][/color][/size][size=2] ([/size][size=2][color=#010001][size=2][color=#010001]currentDisplayConfig[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]DisplayTheme[/color][/size][/color][/size][size=2] == [/size][size=2][color=#010001][size=2][color=#010001]displayThemeId[/color][/size][/color][/size][size=2])
{
[/size][size=2][color=#010001][size=2][color=#010001]displayThemeId[/color][/size][/color][/size][size=2] = [/size][size=2][color=#010001][size=2][color=#010001]displayThemes[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]GetAt[/color][/size][/color][/size][size=2]([/size][size=2][color=#a31515][size=2][color=#a31515]"New Style"[/color][/size][/color][/size][size=2]);
}
[/size][size=2][color=#010001][size=2][color=#010001]currentDisplayConfig[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]DetachDisplayTheme[/color][/size][/color][/size][size=2]();
[/size][size=2][color=#010001][size=2][color=#010001]currentDisplayConfig[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]AttachDisplayTheme[/color][/size][/color][/size][size=2]([/size][size=2][color=#010001][size=2][color=#010001]displayThemeId[/color][/size][/color][/size][size=2]);


[/size][size=2][color=#010001][size=2][color=#010001]trx[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]Commit[/color][/size][/color][/size][size=2]();
}
}
[/size]

Share this post


Link to post
Share on other sites
Jeff H

I was not thinking and passing in the DisplayThemeStyleID

 

But this one changes it to other each time it is called

 

This is a example just to figure it out and knew I had only 2 display themes in drawing.

 

How were you grabbing your display themes?

 

I have to copy it from VS 2010 paste it in VS 2008 so all the code will not all be on one line but it srill does not format.

 


[size=2][[/size][size=2][color=#2b91af][size=2][color=#2b91af]CommandMethod[/color][/size][/color][/size][size=2]([/size][size=2][color=#a31515][size=2][color=#a31515]"ChangeDisplayThemes"[/color][/size][/color][/size][size=2])][/size]
[size=2][color=#0000ff][size=2][color=#0000ff]public[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]void[/color][/size][/color][/size][size=2][color=#010001][size=2][color=#010001]ChangeDisplayThemes[/color][/size][/color][/size][size=2]()[/size]
[size=2]{[/size]
[size=2][color=#010001][size=2][color=#010001]Document[/color][/size][/color][/size][size=2][color=#010001][size=2][color=#010001]doc[/color][/size][/color][/size][size=2] = [/size][size=2][color=#010001][size=2][color=#010001]Application[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]DocumentManager[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]MdiActiveDocument[/color][/size][/color][/size][size=2];[/size]
[size=2][color=#010001][size=2][color=#010001]Database[/color][/size][/color][/size][size=2][color=#010001][size=2][color=#010001]db[/color][/size][/color][/size][size=2] = [/size][size=2][color=#010001][size=2][color=#010001]doc[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]Database[/color][/size][/color][/size][size=2];[/size]
[size=2][color=#010001][size=2][color=#010001]Editor[/color][/size][/color][/size][size=2][color=#010001][size=2][color=#010001]ed[/color][/size][/color][/size][size=2] = [/size][size=2][color=#010001][size=2][color=#010001]doc[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]Editor[/color][/size][/color][/size][size=2];[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]using[/color][/size][/color][/size][size=2] ([/size][size=2][color=#010001][size=2][color=#010001]Transaction[/color][/size][/color][/size][size=2][color=#010001][size=2][color=#010001]trx[/color][/size][/color][/size][size=2] = [/size][size=2][color=#010001][size=2][color=#010001]db[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]TransactionManager[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]StartTransaction[/color][/size][/color][/size][size=2]())[/size]
[size=2]{[/size]
[size=2][color=#010001][size=2][color=#010001]List[/color][/size][/color][/size][size=2]<[/size][size=2][color=#010001][size=2][color=#010001]ObjectId[/color][/size][/color][/size][size=2]> [/size][size=2][color=#010001][size=2][color=#010001]displayThemeIdList[/color][/size][/color][/size][size=2] = [/size][size=2][color=#0000ff][size=2][color=#0000ff]new[/color][/size][/color][/size][size=2][color=#010001][size=2][color=#010001]List[/color][/size][/color][/size][size=2]<[/size][size=2][color=#010001][size=2][color=#010001]ObjectId[/color][/size][/color][/size][size=2]>(); [/size]
[size=2][color=#010001][size=2][color=#010001]BlockTable[/color][/size][/color][/size][size=2][color=#010001][size=2][color=#010001]bt[/color][/size][/color][/size][size=2] = ([/size][size=2][color=#010001][size=2][color=#010001]BlockTable[/color][/size][/color][/size][size=2])[/size][size=2][color=#010001][size=2][color=#010001]trx[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]GetObject[/color][/size][/color][/size][size=2]([/size][size=2][color=#010001][size=2][color=#010001]db[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]BlockTableId[/color][/size][/color][/size][size=2], [/size][size=2][color=#010001][size=2][color=#010001]OpenMode[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]ForRead[/color][/size][/color][/size][size=2]);[/size]
[size=2][color=#010001][size=2][color=#010001]BlockTableRecord[/color][/size][/color][/size][size=2][color=#010001][size=2][color=#010001]modelSpace[/color][/size][/color][/size][size=2] = ([/size][size=2][color=#010001][size=2][color=#010001]BlockTableRecord[/color][/size][/color][/size][size=2])[/size][size=2][color=#010001][size=2][color=#010001]trx[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]GetObject[/color][/size][/color][/size][size=2]([/size][size=2][color=#010001][size=2][color=#010001]bt[/color][/size][/color][/size][size=2][[/size][size=2][color=#010001][size=2][color=#010001]BlockTableRecord[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]ModelSpace[/color][/size][/color][/size][size=2]], [/size][size=2][color=#010001][size=2][color=#010001]OpenMode[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]ForRead[/color][/size][/color][/size][size=2]);[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]foreach[/color][/size][/color][/size][size=2] ([/size][size=2][color=#010001][size=2][color=#010001]ObjectId[/color][/size][/color][/size][size=2][color=#010001][size=2][color=#010001]objId[/color][/size][/color][/size][size=2][color=#0000ff][size=2][color=#0000ff]in[/color][/size][/color][/size][size=2][color=#010001][size=2][color=#010001]modelSpace[/color][/size][/color][/size][size=2])[/size]
[size=2]{[/size]
[size=2][color=#0000ff][size=2][color=#0000ff]if[/color][/size][/color][/size][size=2] ([/size][size=2][color=#010001][size=2][color=#010001]objId[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]ObjectClass[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]Name[/color][/size][/color][/size][size=2] == [/size][size=2][color=#a31515][size=2][color=#a31515]"AecDbDisplayTheme"[/color][/size][/color][/size][size=2])[/size]
[size=2]{[/size]
[size=2][color=#010001][size=2][color=#010001]displayThemeIdList[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]Add[/color][/size][/color][/size][size=2]([/size][size=2][color=#010001][size=2][color=#010001]objId[/color][/size][/color][/size][size=2]);[/size]
[size=2]}[/size]

[size=2]} [/size]
[size=2][color=#010001][size=2][color=#010001]DisplayRepresentationManager[/color][/size][/color][/size][size=2][color=#010001][size=2][color=#010001]disRepMngr[/color][/size][/color][/size][size=2] = [/size][size=2][color=#0000ff][size=2][color=#0000ff]new[/color][/size][/color][/size][size=2][color=#010001][size=2][color=#010001]DisplayRepresentationManager[/color][/size][/color][/size][size=2]([/size][size=2][color=#010001][size=2][color=#010001]db[/color][/size][/color][/size][size=2]);[/size]
[size=2][color=#010001][size=2][color=#010001]DisplayConfiguration[/color][/size][/color][/size][size=2][color=#010001][size=2][color=#010001]currentDisplayConfig[/color][/size][/color][/size][size=2] =[/size]
[size=2][color=#010001][size=2][color=#010001]disRepMngr[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]DisplayConfigurationIdForCurrentViewport[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]GetObject[/color][/size][/color][/size][size=2]([/size][size=2][color=#010001][size=2][color=#010001]OpenMode[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]ForWrite[/color][/size][/color][/size][size=2]) [/size][size=2][color=#0000ff][size=2][color=#0000ff]as[/color][/size][/color][/size][size=2][color=#010001][size=2][color=#010001]DisplayConfiguration[/color][/size][/color][/size][size=2]; [/size]
[size=2][color=#010001][size=2][color=#010001]ObjectId[/color][/size][/color][/size][size=2][color=#010001][size=2][color=#010001]displayThemeId[/color][/size][/color][/size][size=2] = [/size][size=2][color=#010001][size=2][color=#010001]displayThemeIdList[/color][/size][/color][/size][size=2][0];[/size]

[size=2][color=#0000ff][size=2][color=#0000ff]if[/color][/size][/color][/size][size=2] ([/size][size=2][color=#010001][size=2][color=#010001]currentDisplayConfig[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]DisplayTheme[/color][/size][/color][/size][size=2] == [/size][size=2][color=#010001][size=2][color=#010001]displayThemeId[/color][/size][/color][/size][size=2])[/size]
[size=2]{[/size]
[size=2][color=#010001][size=2][color=#010001]displayThemeId[/color][/size][/color][/size][size=2] = [/size][size=2][color=#010001][size=2][color=#010001]displayThemeIdList[/color][/size][/color][/size][size=2][1];[/size]
[size=2]} [/size]

[size=2][color=#010001][size=2][color=#010001]currentDisplayConfig[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]DetachDisplayTheme[/color][/size][/color][/size][size=2](); [/size]
[size=2][color=#010001][size=2][color=#010001]currentDisplayConfig[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]AttachDisplayTheme[/color][/size][/color][/size][size=2]([/size][size=2][color=#010001][size=2][color=#010001]displayThemeId[/color][/size][/color][/size][size=2]); [/size]
[size=2][color=#010001][size=2][color=#010001]trx[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]Commit[/color][/size][/color][/size][size=2]();[/size]
[size=2]}[/size]
[size=2][color=#010001][size=2][color=#010001]ed[/color][/size][/color][/size][size=2].[/size][size=2][color=#010001][size=2][color=#010001]Regen[/color][/size][/color][/size][size=2]();[/size]
[size=2]}[/size]

Share this post


Link to post
Share on other sites
zetazee

Hi Jeff,

 

in order to extract the display themes, I would add these lines of code in the foreach ObjectId objId in modelSpace

 

foreach (ObjectId objId in modelSpace)
{
   //similar to how you extract entities out
   DisplayTheme dt = tm.GetObject(objId, OpenMode.ForRead) as DisplayTheme;

  //i can then print out whether display theme is active or not.
  //ed is of Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
  ed.WriteMessage(dt.IsActive() + "\n");
}

Share this post


Link to post
Share on other sites
zetazee

Hi Jeff,

 

I just tried out the code you pasted. The code works, and it is what I wanted.

 

Many thanks for the kind assistance.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...