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

Layer PlotStyles

7 REPLIES 7
Reply
Message 1 of 8
jimmie_fulton
771 Views, 7 Replies

Layer PlotStyles

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
7 REPLIES 7
Message 2 of 8

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
Message 3 of 8
Anonymous
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
Message 4 of 8

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.
Message 5 of 8
Anonymous
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.
Message 6 of 8

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();
}
}
Message 7 of 8
Anonymous
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.
Message 8 of 8
Dave_B
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}

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