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

Access DWG SummaryInfo Custom Properties

23 REPLIES 23
Reply
Message 1 of 24
CAD4ME
3302 Views, 23 Replies

Access DWG SummaryInfo Custom Properties

Hi

Would really appreciate any help that anybody can give me on this.

I'm trying to programatically access the Custom Properties of a DWG's SummaryInfo, but am constantly coming up against various errors.

From the examples I've found and the other posts I've come across I have to create a new Database object (Autodesk.AutoCAD.DatabaseServices.Database) but when I do I get the following message.

Dim DB as New Database(False, True)

'AccessViolationException was unhandled'
'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'

As you might have guessed I'm new to .NET having done all my previous work in VBA.

Any help will be very much appreciated.

Cheers

G
23 REPLIES 23
Message 2 of 24
Anonymous
in reply to: CAD4ME

try this

Using DB As Database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database
Dim objSumBuilder As DatabaseSummaryInfoBuilder = New DatabaseSummaryInfoBuilder(DB.SummaryInfo)

pat
Message 3 of 24
CAD4ME
in reply to: CAD4ME

Hi Pat

Thanks for the help. I spliced in the code snippet you posted and now the error message reads:-

'TypeInializationException was unhandled'
'The type initializer for 'Module' threw an exception.'

During my searches I came across your post on 'Custom Properties' from Nov 06 and tried that solution as well, with the same error. Do you have a completed sub that I can try and call?

All I've managed to discover so far is that vb does not like the 'database' object that's being defined. If I comment it out then the code steps through without a hitch. I'm using the 'Autodesk.AutoCAD.DatabaseServices.Database' object. That is the right on isn't it?

Thanks for all you help

G
Message 4 of 24
Anonymous
in reply to: CAD4ME

this is getting the properties

Dim Size As New System.Drawing.Size
Dim objStd As StringManipulation.Standards = New StringManipulation.Standards
Dim DB As Database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database
Dim objSumBuilder As DatabaseSummaryInfoBuilder = New DatabaseSummaryInfoBuilder(DB.SummaryInfo)
Dim Dict As StringDictionary = objSumBuilder.CustomProperties
Dim objOldSummary As DatabaseSummaryInfo = DB.SummaryInfo
txtDrawingNo.Text = objStd.RemoveExtension(Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("DWGNAME")) : txtDrawingNo.Enabled = False

'Me.Size = New System.Drawing.Size(425, 390)

txtDrafter.Text = objOldSummary.Author
txtCustomer.Text = objOldSummary.Title
For Each entry As DictionaryEntry In Dict
entry.Key = CType(objStd.CamelCase(CStr(entry.Key)), Object)
Next

For Each entry As DictionaryEntry In Dict
If entry.Key = "office" Then txtOffice.Text = CStr(entry.Value)
If entry.Key = "job number" Then txtJobNumber.Text = CStr(entry.Value)
If entry.Key = "location" Then txtLocation.Text = CStr(entry.Value)
If entry.Key = "drafter date" Then txtDrafterDate.Text = CStr(entry.Value)
If entry.Key = "checker" Then txtCheck.Text = CStr(entry.Value)
If entry.Key = "checker date" Then txtCheckDate.Text = CStr(entry.Value)
If entry.Key = "revised date 1" Then txtRevised1.Text = CStr(entry.Value)
If entry.Key = "revised date 2" Then txtRevised2.Text = CStr(entry.Value)
If entry.Key = "revised date 3" Then txtRevised3.Text = CStr(entry.Value)
If entry.Key = "revised date 4" Then txtRevised4.Text = CStr(entry.Value)
'If entry.Key = "misc" Then txtMisc.Text = CStr(entry.Value) leave if want to use in the future
Next

' Add any initialization after the InitializeComponent() call.

Dim intDummy As Integer = Dict.Count

txtJobNumber.Text = objStd.StringInsertion(txtDrawingNo.Text, "-")
If txtOffice.Text = "" Or txtOffice.Text = "NA" Then
txtOffice.Text = OfficeName()
End If
objOldSummary = Nothing
If txtRevised1.Text = "" Then
txtRevised2.Enabled = False
txtRevised3.Enabled = False
txtRevised4.Enabled = False
End If
If txtRevised2.Text = "" Then
txtRevised3.Enabled = False
txtRevised4.Enabled = False
Else
txtRevised2.Enabled = True
End If
If txtRevised3.Text = "" Then
txtRevised4.Enabled = False
Else
txtRevised3.Enabled = True
End If
If txtRevised4.Text = "" Then
Else
txtRevised3.Enabled = True
End If
LogoInfo()


pat
Message 5 of 24
Anonymous
in reply to: CAD4ME

this is setting the properties
Dim objStd As StringManipulation.Standards = New StringManipulation.Standards
Using DB As Database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database
Dim objSumBuilder As DatabaseSummaryInfoBuilder = New DatabaseSummaryInfoBuilder(DB.SummaryInfo)

Try
'this is updating the drawing properties from what is selected. All the properties have to be
'replaced becasue autocad replaces the properties on any ypdating
objSumBuilder.Author = txtDrafter.Text
objSumBuilder.Title = txtCustomer.Text
If txtOffice.Text = "NA" Then
objSumBuilder.CustomProperties.Item("office") = "NA"
Else
objSumBuilder.CustomProperties.Item("office") = objStd.CamelCase(txtOffice.Text)
End If

objSumBuilder.CustomProperties.Item("job number") = objStd.CamelCase(txtJobNumber.Text)
objSumBuilder.CustomProperties.Item("location") = objStd.CamelCase(txtLocation.Text)
objSumBuilder.CustomProperties.Item("drafter date") = objStd.CamelCase(txtDrafterDate.Text)
objSumBuilder.CustomProperties.Item("checker") = objStd.CamelCase(txtCheck.Text)
objSumBuilder.CustomProperties.Item("checker date") = objStd.CamelCase(txtCheckDate.Text)
objSumBuilder.CustomProperties.Item("revised date 1") = objStd.CamelCase(txtRevised1.Text)
objSumBuilder.CustomProperties.Item("revised date 2") = objStd.CamelCase(txtRevised2.Text)
objSumBuilder.CustomProperties.Item("revised date 3") = objStd.CamelCase(txtRevised3.Text)
objSumBuilder.CustomProperties.Item("revised date 4") = objStd.CamelCase(txtRevised4.Text)
'objSumBuilder.CustomProperties.Item("misc") = txtMisc.Text leave this just in case they want to be able to reuse it in the future

DB.SummaryInfo = objSumBuilder.ToDatabaseSummaryInfo
'this is checking to see if there was any changes to the logo selection box, if so it will
'update all the logos on the approiate tabs, not on the SB and Z tabs
If objValue <> cmbLogo.SelectedItem Then
LogoUpdate()
End If

Catch ex As System.Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Exception")
Finally
objSumBuilder = Nothing
Me.Close()
End Try
End Using
End Sub

pat
Message 6 of 24
Anonymous
in reply to: CAD4ME

See how this will working for you
Hth

~'J'~

Imports System
Imports Autodesk.AutoCAD
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices

Namespace DwgProps

Public Class DwgSummaryInfo
_
Public Sub GetSummInfo()
Dim doc As Document = Application.DocumentManager.MdiActiveDocument

Dim author As String
Dim coms As String
Dim subt As String
Dim titl As String
Dim revnum As String
Dim lastsave As String
Dim keyw As String
Dim hyp As String

With doc.Database.SummaryInfo
author = .Author
coms = .Comments
subt = .Subject
titl = .Title
revnum = .RevisionNumber
lastsave = .LastSavedBy
keyw = .Keywords
hyp = .HyperlinkBase

End With
Dim sbuild As DatabaseSummaryInfoBuilder = New DatabaseSummaryInfoBuilder(doc.Database.SummaryInfo)
Dim Dict As Specialized.StringDictionary = sbuild.CustomProperties
Dim dkey As String
Dim dval As String
For Each entry As DictionaryEntry In Dict
dkey = entry.Key
dval = entry.Value
MsgBox(dkey & " " & dval)
Next

MsgBox(author & vbNewLine _
& coms & vbNewLine _
& subt & vbNewLine _
& revnum & vbNewLine _
& keyw & vbNewLine _
& lastsave & vbNewLine _
& hyp & vbNewLine _
& titl)

End Sub

End Class
End Namespace
Message 7 of 24
CAD4ME
in reply to: CAD4ME

Hi

Thanks for the input. Although the code you supplied is error free when inserted, as soon as I run it and it gets to the call statement, once agasn I get an error. For some reason that's beyond me, it falls over on the:-

'Dim doc As Document = Application.DocumentManager.MdiActiveDocument'

line. Any ideas why?

Thanks

G
Message 8 of 24
CAD4ME
in reply to: CAD4ME

Hi Pat

Thanks for all the code. Unfortunately it still falls over on the Call statement because of the:-

'Dim DB As Database = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocum ent.Database'

line. I can't believe its been made so difficult to acces these custom properties boxes. Anyway, any ideas?

Many thanks

G
Message 9 of 24
Anonymous
in reply to: CAD4ME

why don't you post your code

pat
Message 10 of 24
CAD4ME
in reply to: CAD4ME

Hi

I've done as you suggested and uploaded my code. Because its a bit lengthy, I've attached it as a word document.

All I'm trying to do, is take a load of information from a central database (subsituted with a dummy sub for now) and add i to the custom properties of a drawing. So in case I've screwed up somewhere else, I've attache the whole thing. I am using multiple modules for this, but I've cut and paste them all together fir simplicity.

Thanks again.

G
Message 11 of 24
Anonymous
in reply to: CAD4ME

change Dim DB As Database to
Using DB As Database

at the end of the sub put end using

see if that works

pat
Message 12 of 24
CAD4ME
in reply to: CAD4ME

No luck I'm afraid. Still getting the 'TypeInializationException was unhandled' error.

G
Message 13 of 24
Anonymous
in reply to: CAD4ME

Hi. Sorry to say this, but it looks like you're
in this way over your head, and probably need
to spend a little more time getting familiar with
some of the basics of using the managed API.

You are trying to use the Managed .NET API
for AutoCAD, from an external process.

You can't do that.

You can only use the managed API from a
a DLL that's loaded into AutoCAD.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5513468@discussion.autodesk.com...
No luck I'm afraid. Still getting the 'TypeInializationException was unhandled' error.

G
Message 14 of 24
Anonymous
in reply to: CAD4ME

Tony, could he put that in a DLL that is loaded upon opening and then get what he wants from using an event.

He would have to redo his code of cours


pat
Message 15 of 24
Anonymous
in reply to: CAD4ME

He can build a COM server that loads into
AutoCAD and uses the managed API, and
expose it to an external client.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5513775@discussion.autodesk.com...
Tony, could he put that in a DLL that is loaded upon opening and then get what he wants from using an event.

He would have to redo his code of cours


pat
Message 16 of 24
CAD4ME
in reply to: CAD4ME

Many thanks to all who've responded to my plea. I think I'm going ot shelve .NET for now and go onto VB6 instead. A much smaller step from VBA. And I managed to access the Custom Properties without any hassle too.

Thanks again to all.

Cheers

G
Message 17 of 24
NathTay
in reply to: CAD4ME

Are your issues with .NET in general or just the AutoCAD .NET API. If it is the latter you can still use the ActiveX API with a .NET language.

Regards - Nathan
Message 18 of 24
CAD4ME
in reply to: CAD4ME

Hi

Its both I'm afraid. I've been manipulating AutoCAD through VBA for over a year now with great sucsess. I thought that AutoCAD 2007 now being .NET enabled, would allow for far greater flexibility but there is precious little documentation around, tutorials etc, about driving AutoCAD from VB.NET.

So seeing that I was struggling with the new language, the powers that be took me off it and gave VB6 instead. If you know of any material that covers AutoCAD and VB.NET (not C#) I'd be most interested in reading it, as its still my ultimate goal.

I did get hold of a copy of the AutoCAD 2007 API Training Labs but the code examples in there a) don't work, even when cut and paste, and b) don't match the example files that go with them. Brilliant!

Cheers

G
Message 19 of 24
simonsson
in reply to: CAD4ME

I'm having the same kind of problem. I'm using C#. I want to access (read/write) custom file properties in a DWG file from an external process I guess (without starting AutoCAD or anything). So, is this possible in any way?
Message 20 of 24
simonsson
in reply to: CAD4ME

I guess using the ActiveX API is a solution if I want to reach a dwg-file without AutoCAD started. What references should be added for this? And does anyone have any code examples explaining how to read/edit custom dwg file properties that way? I'm trying to solve this using C#, but I'm stuck.

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