.NET

Reply
Active Contributor
jimmie_fulton
Posts: 44
Registered: ‎04-06-2005
Message 1 of 8 (326 Views)

Layer PlotStyles

326 Views, 7 Replies
12-29-2005 05:58 PM
I'm trying to set plotstyles on layers (I'm using STBs), and I'm at the head-scratching point right now.

First, I'd like to determine if the correct STB is being used. I'm checking the database.Stylesheet property, but it always comes up empty. Is this the right place to check? Is this functionality broken?

Also, there are cases where a plotstyle has not been applied to any layers yet, in which case I get a "eKeyNotFound" error when setting my layer.PlotStyleName. It's like the plotstyle needs to be loaded first (even though I can see it in the list of available plotstyles in the layer manager). I've taken care of this before in vba by using a sendcommand to set the plotstyle on one layer first, but there has to be a better way.

Any input appreciated.

Thanks

Jimmie
Active Contributor
jimmie_fulton
Posts: 44
Registered: ‎04-06-2005
Message 2 of 8 (326 Views)

Re: Layer PlotStyles

12-30-2005 10:30 AM in reply to: jimmie_fulton
Nevermind on the portion about setting layer.PlotStyleName. I found the solution (workaround) in the thread titled "Cranky setting of layer PlotStyleName property - any solutions?" in the VBA forum. Basically, create a temporary point object in the drawing, set it's PlotStyleName to the one you want to load, and then delete the object. This causes the PlotStyle to be loaded from the STB. Once loaded, you can apply to a layer. Seems like you shouldn't have to do all of that.

My first question... how do you tell what the active STB is still stands. I'm hoping not to rely on COM objects to get this info.

Thanks

Jimmie
*TomD
Message 3 of 8 (326 Views)

Re: Layer PlotStyles

12-30-2005 11:55 AM in reply to: jimmie_fulton
I haven't coded anything to do it, so I could be wrong, but that should be
in with the PageSetup. There really isn't an 'active' STB.

wrote in message news:5047980@discussion.autodesk.com...
Nevermind on the portion about setting layer.PlotStyleName. I found the
solution (workaround) in the thread titled "Cranky setting of layer
PlotStyleName property - any solutions?" in the VBA forum. Basically,
create a temporary point object in the drawing, set it's PlotStyleName to
the one you want to load, and then delete the object. This causes the
PlotStyle to be loaded from the STB. Once loaded, you can apply to a layer.
Seems like you shouldn't have to do all of that.

My first question... how do you tell what the active STB is still stands.
I'm hoping not to rely on COM objects to get this info.

Thanks

Jimmie
Active Contributor
jimmie_fulton
Posts: 44
Registered: ‎04-06-2005
Message 4 of 8 (326 Views)

Re: Layer PlotStyles

12-30-2005 01:35 PM in reply to: jimmie_fulton
Thanks for your reply!

When selecting a plot style in the layer manager, you can select the "Active Plot Style Table" in that dialog. This is the style table in which the plot styles would be available. I'd like to be able to figure out which one is active so that I can assume which plot styles can be applied.
*TomD
Message 5 of 8 (326 Views)

Re: Layer PlotStyles

01-10-2006 08:01 AM in reply to: jimmie_fulton
Well, they're only active for the purpose of that pagesetup. Basically at
any time the plot style table can be changed. I think the current/active
plot style table can be obtained from the Layout object. (Word of caution,
I don't use .NET, so my thoughts are based on VBA, which is similar but
apparently has significant differences, too.)

FWIW, in my opinion, that is where Adesk went wrong with the whole idea.
They should have made each layout store pen styles for each layer instead of
providing for using multiple plot style tables. That would have provided
virtually the same functionality with much less confusion and possible
headache.

wrote in message news:5048094@discussion.autodesk.com...
Thanks for your reply!

When selecting a plot style in the layer manager, you can select the "Active
Plot Style Table" in that dialog. This is the style table in which the
plot styles would be available. I'd like to be able to figure out which one
is active so that I can assume which plot styles can be applied.
Active Contributor
jimmie_fulton
Posts: 44
Registered: ‎04-06-2005
Message 6 of 8 (326 Views)

Re: Layer PlotStyles

01-11-2006 02:47 PM in reply to: jimmie_fulton
Thanks for the reply. I had figured this out a while ago... should have posted the answer. You're right. A different Plot Style table is active for each layout, and is available through the Layout object (retrieved through the current LayoutManager). Setting this value is done through the current PlotSettingsValidator object.

Here is some sample code to get/set this value for anyone else who might need this in the future:

[CommandMethod("test")]
public static void Test()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

Database db = HostApplicationServices.WorkingDatabase;
LayoutManager lm = LayoutManager.Current;

using (Transaction trans = db.TransactionManager.StartTransaction())
{
PlotSettingsValidator psv = PlotSettingsValidator.Current;
Layout layout = (Layout)trans.GetObject(lm.GetLayoutId("Model"), OpenMode.ForWrite);
ed.WriteMessage(layout.CurrentStyleSheet + "\n");
psv.SetCurrentStyleSheet(layout, "Gensler Plot Style.stb");
ed.WriteMessage(layout.CurrentStyleSheet + "\n");

trans.Commit();
}
}
*TomD
Message 7 of 8 (326 Views)

Re: Layer PlotStyles

01-13-2006 03:43 AM in reply to: jimmie_fulton
Glad you got it worked out and thanks for posting the code.

wrote in message news:5056739@discussion.autodesk.com...
Thanks for the reply. I had figured this out a while ago... should have
posted the answer. You're right. A different Plot Style table is active
for each layout, and is available through the Layout object (retrieved
through the current LayoutManager). Setting this value is done through the
current PlotSettingsValidator object.
Contributor
Dave_B
Posts: 24
Registered: ‎03-25-2009
Message 8 of 8 (233 Views)

Re: Layer PlotStyles

08-23-2011 01:07 PM in reply to: jimmie_fulton

The probelm still exists 5 years later.

 

Here is a brute force workaround for VB.NET.  I'm posting it only to help the novice who needs a quick way to get their VB.NET program working now without having to drop everything and study up on the subject.

 

This subroutine can be added to a module and called from your main program by:

DrawLinechgPSerase()

 

The code ctreates a line in model space, changes the line's plot style to one your program needs to use later, then erases the line.  The program repeats for each plot style name listed in the array.

 

{code

 

' workaround reqd to get Acad PStable dictionary to "see" a previously unused plot style name

Public Sub DrawLinechgPSerase()

Dim validplotstylearray As Object

Dim i As Integer

 

Dim DBcur As Database = HostApplicationServices.WorkingDatabase

' Enter your problem Plot Style names here..

validplotstylearray = New Object() {"Normal", "StyleA", "StyleB", "StyleC"}

 

For i = 0 To UBound(validplotstylearray)

Dim myLine As New Line(Point3d.Origin, New Point3d(4, 5, 6))

 

Using myTrans As Transaction = DBcur.TransactionManager.StartTransaction

Dim myBT As BlockTable = DBcur.BlockTableId.GetObject(OpenMode.ForRead)

Dim myModelSpace As BlockTableRecord = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)

myModelSpace.AppendEntity(myLine)

myLine.PlotStyleName = validplotstylearray(i)

myTrans.AddNewlyCreatedDBObject(myLine, True)

myTrans.Commit()

End Using

 

Using myTrans As Transaction = DBcur.TransactionManager.StartTransaction

Dim myBT As BlockTable = DBcur.BlockTableId.GetObject(OpenMode.ForRead)

Dim myModelSpace As BlockTableRecord = myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)

myLine.Erase()

myTrans.Commit()

End Using

Next

 

End Sub

 

code}

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.