VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Loading Named Plot Styles and Linetypes?

5 REPLIES 5
Reply
Message 1 of 6
Anonymous
259 Views, 5 Replies

Loading Named Plot Styles and Linetypes?

Does anyone know how I can load a .stb file in a drawing along with all the
Named Plot Styles that are contained in the .stb?
The same for Linetypes in a .lin?

I am wanting to assign Plot Styles and linetypes to layers in a drawing, but
cannot automate this through VBA without the individual Named Plot Styles or
Linetypes loaded in the drawing.

Any help would be greatly appreciated.
Jonathan Stewart
5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: Anonymous

Jonathan -

You don't really "load" plot styles into the drawing. There's simply a
dictionary that lists the plot style names available in the drawing, but the
plot style information still comes directly from the .stb file. What I do is
keep a master file with all the plot styles I use, then use the following
code to get the plot style references into my other drawings:

Public Function dbx_copy_pstyle(filename As String, pstyle As String)
On Error GoTo Handler
Dim dxbdoc As New AXDB15Lib.AxDbDocument
Dim xtyps As Variant, xvals As Variant
Dim sourcedic As AcadDictionary
Dim destdic As AcadDictionary
Dim sourcerec As AcadObject
Set dxbdoc =
AcadApplication.GetInterfaceObject("ObjectDBX.AxDbDocument")
dxbdoc.Open filename
Set sourcedic = dxbdoc.Dictionaries("acad_plotstylename")
Dim objarr(0) As AcadObject
Set sourcerec = sourcedic(pstyle)
Set objarr(0) = sourcerec
Set destdic = ActiveDocument.Dictionaries("acad_plotstylename")
dxbdoc.CopyObjects objarr, destdic
Set dxbdoc = Nothing
Set sourcedic = Nothing
Set destdic = Nothing
Exit Function
Handler:
If Err.number <> 0 Then
ActiveDocument.Utility.Prompt vbCrLf & Err.number & " " &
Err.Description
err.clear
End If
End Function

Linetypes are a lot easier. Use something like this:

Dim linetypename as string
linetypename = "hidden2"
Dim ltyp As AcadLineType
With ActiveDocument.Linetypes
Set ltyp = .Item(linetypename)
If Err.number <> 0 Then
Err.Clear
.Add (linetypename)
End If
End With
Set ltyp = Nothing

Hope this helps




"Jonathan Stewart" wrote in message
news:583E478FA870744D1C19EA39DD370507@in.WebX.maYIadrTaRb...
> Does anyone know how I can load a .stb file in a drawing along with all
the
> Named Plot Styles that are contained in the .stb?
> The same for Linetypes in a .lin?
>
> I am wanting to assign Plot Styles and linetypes to layers in a drawing,
but
> cannot automate this through VBA without the individual Named Plot Styles
or
> Linetypes loaded in the drawing.
>
> Any help would be greatly appreciated.
> Jonathan Stewart
>
>
Message 3 of 6
Anonymous
in reply to: Anonymous

Tony,

Thanks for the response.

I do have the linetypes working, but the plot styles are blowing me away. Is
there additional Type Libraries that I should be referencing for this code?
Excuse my ignorance, but I'm only a "novice/intermediate" programmer. I've
never used the AcadDictionary.

Thanks,

Jonathan

"Tony Burba" wrote in message
news:D042D083D025496509BD078FE46F1523@in.WebX.maYIadrTaRb...
> Jonathan -
>
> You don't really "load" plot styles into the drawing. There's simply a
> dictionary that lists the plot style names available in the drawing, but
the
> plot style information still comes directly from the .stb file. What I do
is
> keep a master file with all the plot styles I use, then use the following
> code to get the plot style references into my other drawings:
>
> Public Function dbx_copy_pstyle(filename As String, pstyle As String)
> On Error GoTo Handler
> Dim dxbdoc As New AXDB15Lib.AxDbDocument
> Dim xtyps As Variant, xvals As Variant
> Dim sourcedic As AcadDictionary
> Dim destdic As AcadDictionary
> Dim sourcerec As AcadObject
> Set dxbdoc =
> AcadApplication.GetInterfaceObject("ObjectDBX.AxDbDocument")
> dxbdoc.Open filename
> Set sourcedic = dxbdoc.Dictionaries("acad_plotstylename")
> Dim objarr(0) As AcadObject
> Set sourcerec = sourcedic(pstyle)
> Set objarr(0) = sourcerec
> Set destdic = ActiveDocument.Dictionaries("acad_plotstylename")
> dxbdoc.CopyObjects objarr, destdic
> Set dxbdoc = Nothing
> Set sourcedic = Nothing
> Set destdic = Nothing
> Exit Function
> Handler:
> If Err.number <> 0 Then
> ActiveDocument.Utility.Prompt vbCrLf & Err.number & " " &
> Err.Description
> err.clear
> End If
> End Function
>
> Linetypes are a lot easier. Use something like this:
>
> Dim linetypename as string
> linetypename = "hidden2"
> Dim ltyp As AcadLineType
> With ActiveDocument.Linetypes
> Set ltyp = .Item(linetypename)
> If Err.number <> 0 Then
> Err.Clear
> .Add (linetypename)
> End If
> End With
> Set ltyp = Nothing
>
> Hope this helps
>
>
>
>
> "Jonathan Stewart" wrote in message
> news:583E478FA870744D1C19EA39DD370507@in.WebX.maYIadrTaRb...
> > Does anyone know how I can load a .stb file in a drawing along with all
> the
> > Named Plot Styles that are contained in the .stb?
> > The same for Linetypes in a .lin?
> >
> > I am wanting to assign Plot Styles and linetypes to layers in a drawing,
> but
> > cannot automate this through VBA without the individual Named Plot
Styles
> or
> > Linetypes loaded in the drawing.
> >
> > Any help would be greatly appreciated.
> > Jonathan Stewart
> >
> >
>
>
Message 4 of 6
Anonymous
in reply to: Anonymous

Johnathan -

Sorry. Before you can use the dbx functions, you need to register the dll.
Go to the Windows command prompt (not the AutoCad command line, but the
Windows Dos-style command interface) and run the following:

regsvr32 /s "c:\program files\Autocadpath\axdb15.dll"

(in place of AutoCadpath put the path to the acad application directory)

Then add references to ObjectDbx 1.0 Type Library to your project.

Dictionaries are where AutoCad stores non-graphic information in your
drawing. See developer documentation for more info.

Tony


"Jonathan Stewart" wrote in message
news:62CAE62C813B0E285717901BD112FF51@in.WebX.maYIadrTaRb...
> Tony,
>
> Thanks for the response.
>
> I do have the linetypes working, but the plot styles are blowing me away.
Is
> there additional Type Libraries that I should be referencing for this
code?
> Excuse my ignorance, but I'm only a "novice/intermediate" programmer.
I've
> never used the AcadDictionary.
>
> Thanks,
>
> Jonathan
>
> "Tony Burba" wrote in message
> news:D042D083D025496509BD078FE46F1523@in.WebX.maYIadrTaRb...
> > Jonathan -
> >
> > You don't really "load" plot styles into the drawing. There's simply a
> > dictionary that lists the plot style names available in the drawing, but
> the
> > plot style information still comes directly from the .stb file. What I
do
> is
> > keep a master file with all the plot styles I use, then use the
following
> > code to get the plot style references into my other drawings:
> >
> > Public Function dbx_copy_pstyle(filename As String, pstyle As String)
> > On Error GoTo Handler
> > Dim dxbdoc As New AXDB15Lib.AxDbDocument
> > Dim xtyps As Variant, xvals As Variant
> > Dim sourcedic As AcadDictionary
> > Dim destdic As AcadDictionary
> > Dim sourcerec As AcadObject
> > Set dxbdoc =
> > AcadApplication.GetInterfaceObject("ObjectDBX.AxDbDocument")
> > dxbdoc.Open filename
> > Set sourcedic = dxbdoc.Dictionaries("acad_plotstylename")
> > Dim objarr(0) As AcadObject
> > Set sourcerec = sourcedic(pstyle)
> > Set objarr(0) = sourcerec
> > Set destdic = ActiveDocument.Dictionaries("acad_plotstylename")
> > dxbdoc.CopyObjects objarr, destdic
> > Set dxbdoc = Nothing
> > Set sourcedic = Nothing
> > Set destdic = Nothing
> > Exit Function
> > Handler:
> > If Err.number <> 0 Then
> > ActiveDocument.Utility.Prompt vbCrLf & Err.number & " " &
> > Err.Description
> > err.clear
> > End If
> > End Function
> >
> > Linetypes are a lot easier. Use something like this:
> >
> > Dim linetypename as string
> > linetypename = "hidden2"
> > Dim ltyp As AcadLineType
> > With ActiveDocument.Linetypes
> > Set ltyp = .Item(linetypename)
> > If Err.number <> 0 Then
> > Err.Clear
> > .Add (linetypename)
> > End If
> > End With
> > Set ltyp = Nothing
> >
> > Hope this helps
> >
> >
> >
> >
> > "Jonathan Stewart" wrote in message
> > news:583E478FA870744D1C19EA39DD370507@in.WebX.maYIadrTaRb...
> > > Does anyone know how I can load a .stb file in a drawing along with
all
> > the
> > > Named Plot Styles that are contained in the .stb?
> > > The same for Linetypes in a .lin?
> > >
> > > I am wanting to assign Plot Styles and linetypes to layers in a
drawing,
> > but
> > > cannot automate this through VBA without the individual Named Plot
> Styles
> > or
> > > Linetypes loaded in the drawing.
> > >
> > > Any help would be greatly appreciated.
> > > Jonathan Stewart
> > >
> > >
> >
> >
>
>
Message 5 of 6
Anonymous
in reply to: Anonymous

Tony,
Ok, I've regestered the dll, and added the references.

I must be missing something else. Do I set the filename to a drawing file
or .stb file?
And is this code for adding just one individual pstyle?

I just really feel clueless.
Jonathan




"Tony Burba" wrote in message
news:D53C656397095D738BAFDCCB042DAB42@in.WebX.maYIadrTaRb...
> Johnathan -
>
> Sorry. Before you can use the dbx functions, you need to register the dll.
> Go to the Windows command prompt (not the AutoCad command line, but the
> Windows Dos-style command interface) and run the following:
>
> regsvr32 /s "c:\program files\Autocadpath\axdb15.dll"
>
> (in place of AutoCadpath put the path to the acad application directory)
>
> Then add references to ObjectDbx 1.0 Type Library to your project.
>
> Dictionaries are where AutoCad stores non-graphic information in your
> drawing. See developer documentation for more info.
>
> Tony
>
>
> "Jonathan Stewart" wrote in message
> news:62CAE62C813B0E285717901BD112FF51@in.WebX.maYIadrTaRb...
> > Tony,
> >
> > Thanks for the response.
> >
> > I do have the linetypes working, but the plot styles are blowing me
away.
> Is
> > there additional Type Libraries that I should be referencing for this
> code?
> > Excuse my ignorance, but I'm only a "novice/intermediate" programmer.
> I've
> > never used the AcadDictionary.
> >
> > Thanks,
> >
> > Jonathan
> >
> > "Tony Burba" wrote in message
> > news:D042D083D025496509BD078FE46F1523@in.WebX.maYIadrTaRb...
> > > Jonathan -
> > >
> > > You don't really "load" plot styles into the drawing. There's simply a
> > > dictionary that lists the plot style names available in the drawing,
but
> > the
> > > plot style information still comes directly from the .stb file. What I
> do
> > is
> > > keep a master file with all the plot styles I use, then use the
> following
> > > code to get the plot style references into my other drawings:
> > >
> > > Public Function dbx_copy_pstyle(filename As String, pstyle As String)
> > > On Error GoTo Handler
> > > Dim dxbdoc As New AXDB15Lib.AxDbDocument
> > > Dim xtyps As Variant, xvals As Variant
> > > Dim sourcedic As AcadDictionary
> > > Dim destdic As AcadDictionary
> > > Dim sourcerec As AcadObject
> > > Set dxbdoc =
> > > AcadApplication.GetInterfaceObject("ObjectDBX.AxDbDocument")
> > > dxbdoc.Open filename
> > > Set sourcedic = dxbdoc.Dictionaries("acad_plotstylename")
> > > Dim objarr(0) As AcadObject
> > > Set sourcerec = sourcedic(pstyle)
> > > Set objarr(0) = sourcerec
> > > Set destdic = ActiveDocument.Dictionaries("acad_plotstylename")
> > > dxbdoc.CopyObjects objarr, destdic
> > > Set dxbdoc = Nothing
> > > Set sourcedic = Nothing
> > > Set destdic = Nothing
> > > Exit Function
> > > Handler:
> > > If Err.number <> 0 Then
> > > ActiveDocument.Utility.Prompt vbCrLf & Err.number & " " &
> > > Err.Description
> > > err.clear
> > > End If
> > > End Function
> > >
> > > Linetypes are a lot easier. Use something like this:
> > >
> > > Dim linetypename as string
> > > linetypename = "hidden2"
> > > Dim ltyp As AcadLineType
> > > With ActiveDocument.Linetypes
> > > Set ltyp = .Item(linetypename)
> > > If Err.number <> 0 Then
> > > Err.Clear
> > > .Add (linetypename)
> > > End If
> > > End With
> > > Set ltyp = Nothing
> > >
> > > Hope this helps
> > >
> > >
> > >
> > >
> > > "Jonathan Stewart" wrote in message
> > > news:583E478FA870744D1C19EA39DD370507@in.WebX.maYIadrTaRb...
> > > > Does anyone know how I can load a .stb file in a drawing along with
> all
> > > the
> > > > Named Plot Styles that are contained in the .stb?
> > > > The same for Linetypes in a .lin?
> > > >
> > > > I am wanting to assign Plot Styles and linetypes to layers in a
> drawing,
> > > but
> > > > cannot automate this through VBA without the individual Named Plot
> > Styles
> > > or
> > > > Linetypes loaded in the drawing.
> > > >
> > > > Any help would be greatly appreciated.
> > > > Jonathan Stewart
> > > >
> > > >
> > >
> > >
> >
> >
>
>
Message 6 of 6
Anonymous
in reply to: Anonymous

Jonathan -

The code is for copying a single plotstyle reference from one drawing to
another, using DBX to read the source drawing without actually opening it..

For whatever reason, you can't use VBA to assign a plot style to a layer
unless the plot style is already listed in the drawing in a dictionary
called "acad_plotstylename."

For example, say you need to assign the plot style "Black" to the layer
"Fred", but the style "Black" is not already in use in the drawing. If you
try to assign the plotstyle using the following code, you'll get an error:

ActiveDocument.Layers("Fred").Plotstylename = "Black"

I know no way of accessing the .stb file directly, so I create a master .dwg
file containing layers that use all the plot styles in the .stb file. Thus
all the plotstyles in the .stb file are listed in "acad_plotstylename"
dictionary of the master file. I then use the dbx_copy_pstyle to copy the
plot style references from the master file into any other drawing in which I
need them.

Here's how I do it:

On error resume next
ActiveDocument.Layers("Fred").Plotstylename = "Black"
If err.number <> 0 then
Err.clear
dbx_copy_pstyle masterfilename, "Black"
ActiveDocument.Layers("Fred").Plotstylename = "Black"
End if

What happens is that if the plotstylename assignment fails, dbx_copy_pstyle
copies the plot style reference into the drawing, then it tries the
assignment again.

Keep in mind that nothing except the plotstyle name is stored in the drawing
file. All the actual plot style information is taken from the .stb file. You
just have to have the plotstyle listed in the drawing to be able to use it.

I hope I'm helping you rather than confusing you more. This is a pretty
roundabout way of doing something that should be simple, but AutoDesk forgot
to provide the simple way.

Tony


"Jonathan Stewart" wrote in message
news:A22EFFEB2F584BC1B35E7A1FF35CDC94@in.WebX.maYIadrTaRb...
> Tony,
> Ok, I've regestered the dll, and added the references.
>
> I must be missing something else. Do I set the filename to a drawing file
> or .stb file?
> And is this code for adding just one individual pstyle?
>
> I just really feel clueless.
> Jonathan
>
>
>
>
> "Tony Burba" wrote in message
> news:D53C656397095D738BAFDCCB042DAB42@in.WebX.maYIadrTaRb...
> > Johnathan -
> >
> > Sorry. Before you can use the dbx functions, you need to register the
dll.
> > Go to the Windows command prompt (not the AutoCad command line, but the
> > Windows Dos-style command interface) and run the following:
> >
> > regsvr32 /s "c:\program files\Autocadpath\axdb15.dll"
> >
> > (in place of AutoCadpath put the path to the acad application directory)
> >
> > Then add references to ObjectDbx 1.0 Type Library to your project.
> >
> > Dictionaries are where AutoCad stores non-graphic information in your
> > drawing. See developer documentation for more info.
> >
> > Tony
> >
> >
> > "Jonathan Stewart" wrote in message
> > news:62CAE62C813B0E285717901BD112FF51@in.WebX.maYIadrTaRb...
> > > Tony,
> > >
> > > Thanks for the response.
> > >
> > > I do have the linetypes working, but the plot styles are blowing me
> away.
> > Is
> > > there additional Type Libraries that I should be referencing for this
> > code?
> > > Excuse my ignorance, but I'm only a "novice/intermediate" programmer.
> > I've
> > > never used the AcadDictionary.
> > >
> > > Thanks,
> > >
> > > Jonathan
> > >
> > > "Tony Burba" wrote in message
> > > news:D042D083D025496509BD078FE46F1523@in.WebX.maYIadrTaRb...
> > > > Jonathan -
> > > >
> > > > You don't really "load" plot styles into the drawing. There's simply
a
> > > > dictionary that lists the plot style names available in the drawing,
> but
> > > the
> > > > plot style information still comes directly from the .stb file. What
I
> > do
> > > is
> > > > keep a master file with all the plot styles I use, then use the
> > following
> > > > code to get the plot style references into my other drawings:
> > > >
> > > > Public Function dbx_copy_pstyle(filename As String, pstyle As
String)
> > > > On Error GoTo Handler
> > > > Dim dxbdoc As New AXDB15Lib.AxDbDocument
> > > > Dim xtyps As Variant, xvals As Variant
> > > > Dim sourcedic As AcadDictionary
> > > > Dim destdic As AcadDictionary
> > > > Dim sourcerec As AcadObject
> > > > Set dxbdoc =
> > > > AcadApplication.GetInterfaceObject("ObjectDBX.AxDbDocument")
> > > > dxbdoc.Open filename
> > > > Set sourcedic = dxbdoc.Dictionaries("acad_plotstylename")
> > > > Dim objarr(0) As AcadObject
> > > > Set sourcerec = sourcedic(pstyle)
> > > > Set objarr(0) = sourcerec
> > > > Set destdic = ActiveDocument.Dictionaries("acad_plotstylename")
> > > > dxbdoc.CopyObjects objarr, destdic
> > > > Set dxbdoc = Nothing
> > > > Set sourcedic = Nothing
> > > > Set destdic = Nothing
> > > > Exit Function
> > > > Handler:
> > > > If Err.number <> 0 Then
> > > > ActiveDocument.Utility.Prompt vbCrLf & Err.number & " " &
> > > > Err.Description
> > > > err.clear
> > > > End If
> > > > End Function
> > > >
> > > > Linetypes are a lot easier. Use something like this:
> > > >
> > > > Dim linetypename as string
> > > > linetypename = "hidden2"
> > > > Dim ltyp As AcadLineType
> > > > With ActiveDocument.Linetypes
> > > > Set ltyp = .Item(linetypename)
> > > > If Err.number <> 0 Then
> > > > Err.Clear
> > > > .Add (linetypename)
> > > > End If
> > > > End With
> > > > Set ltyp = Nothing
> > > >
> > > > Hope this helps
> > > >
> > > >
> > > >
> > > >
> > > > "Jonathan Stewart" wrote in message
> > > > news:583E478FA870744D1C19EA39DD370507@in.WebX.maYIadrTaRb...
> > > > > Does anyone know how I can load a .stb file in a drawing along
with
> > all
> > > > the
> > > > > Named Plot Styles that are contained in the .stb?
> > > > > The same for Linetypes in a .lin?
> > > > >
> > > > > I am wanting to assign Plot Styles and linetypes to layers in a
> > drawing,
> > > > but
> > > > > cannot automate this through VBA without the individual Named Plot
> > > Styles
> > > > or
> > > > > Linetypes loaded in the drawing.
> > > > >
> > > > > Any help would be greatly appreciated.
> > > > > Jonathan Stewart
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost