I am working on a project that will create a sheet set, add the number of sheets specified in prompt into the sheet set and edit custom properties.
first I am a beginner so please be patient with me.
second the first issue that I am having is how to pull the number of sheets from the prompt and tell it to add that many sheets.
I would assume that it would start like this
For Each ??
sheetset.addnewsheet()
Next
Please look at code posted below for prompt I have it as an integer but maybe it should be numerical
Third the second issue that I am having is the editing of custom properties.
I am using a template that already has the custom properties in, which I want to prompt the user for what the value of the custom proerty should be
again see code posted below for prompt
any assistance is greatful
'Specifies the command to use <CommandMethod("psetup")> _ Public Sub plansetup() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim ed As Editor = doc.Editor 'Get a reference to the Sheet Set Manager object Dim ssm As IAcSmSheetSetMgr ssm = New AcSmSheetSetMgr 'Sets save location and filename of the sheet set Dim ssn As SaveFileDialog = New SaveFileDialog(title:="Save Sheet Set", defaultName:="", dialogName:="Save Sheet Set", extension:="dst", flags:=SaveFileDialog.SaveFileDialogFlags.NoFtpSites) ssn.ShowDialog() 'Create a new sheet set file Dim ssdb As AcSmDatabase ssdb = ssm.CreateDatabase(ssn.Filename, "M:\CAD Management\CAD Files\Template\Sheetsets\New Sheet Set (1).dst", True) 'Locks the database ssdb.LockDb(ssdb) 'Sets the name and description ssdb.SetName(name:=ssn.Filename.ToString) ssdb.SetDesc(desc:="New Sheet Set") Dim ss As AcSmSheetSet = ssdb.GetSheetSet 'Enter the number of sheets Dim nos As New PromptIntegerOptions(vbLf & "Enter the Number of Sheets:") Dim nor As PromptIntegerResult = ed.GetInteger(nos) 'Enter the name of the Author Dim apn As New PromptStringOptions(vbLf & "Enter Name of Author:") Dim apr As PromptResult = ed.GetString(apn) For Each i As Integer ss.AddNewSheet() Next 'Unlocks the database ssdb.UnlockDb(ssdb) 'Closes the database ssm.Close(ssdb) End Sub
Solved! Go to Solution.
Not "For each I as integer" (you should be seeing a compiler error on that)
When traversing a collection you use "For Each item as Type in Collection"
When performing a task a certain number of times you use "For I as Integer = 0 to nos"
Or in your case you'd probably do 1 to nos
Try looking at this Through The Interface post:
He is reading data from a sheet set as opposed to creating one, but it might help. (It's in C#, this is a pretty good translator http://www.developerfusion.com/tools/convert/csharp-to-vb/)
thank you
however would I not want to do
For i as integer = 1 to nor rather then nos
another thing is that when I put in the above code it says:
using nor "promptresult can not be converted to integer"
using nos "promptintegeroptions can not be converted to integer"
I have looked at the through the interface article, but have not had a chance to really go through and analys the code and try to make sense of it
I am also having issues just trying to get a sheet added to the sheet set with out the prompt and it doesn't add the sheet.
I also do not get any errors on it so my only guess is that I am missing something.
here is updated code:
Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports ACSMCOMPONENTS18Lib Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Windows Public Class Class1 'Specifies the command to use <CommandMethod("psetup")> _ Public Sub plansetup() Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim ed As Editor = doc.Editor 'Get a reference to the Sheet Set Manager object Dim ssm As IAcSmSheetSetMgr ssm = New AcSmSheetSetMgr 'Sets save location and filename of the sheet set Dim ssn As SaveFileDialog = New SaveFileDialog(title:="Save Sheet Set", defaultName:="", dialogName:="Save Sheet Set", extension:="dst", flags:=SaveFileDialog.SaveFileDialogFlags.NoFtpSites) ssn.ShowDialog() 'Create a new sheet set file Dim ssdb As AcSmDatabase ssdb = ssm.CreateDatabase(ssn.Filename, "M:\CAD Management\CAD Files\Template\Sheetsets\New Sheet Set (1).dst", True) 'Locks the database ssdb.LockDb(ssdb) 'Sets the name and description ssdb.SetName(name:=ssn.Filename.ToString) ssdb.SetDesc(desc:="New Sheet Set") Dim ss As AcSmSheetSet = ssdb.GetSheetSet 'Enter the number of sheets Dim nos As New PromptIntegerOptions(vbLf & "Enter the Number of Sheets:") Dim nor As PromptResult = ed.GetInteger(nos) 'Enter the initials of the drafter Dim apn As New PromptStringOptions(vbLf & "Enter Initials of Drafter:") Dim apr As PromptResult = ed.GetString(apn) 'Enter the project phase Dim pp As New PromptStringOptions(vbLf & "Enter the Project Phase:") pp.AllowSpaces = True Dim ppr As PromptResult = ed.GetString(pp) 'Enter the Job Date Dim jd As New PromptStringOptions(vbLf & "Enter the Job Date:") jd.AllowSpaces = True Dim jdr As PromptResult = ed.GetString(jd) 'Enter the Job Number Dim jn As New PromptStringOptions(vbLf & "Enter the Job Name:") jn.AllowSpaces = True Dim jnr As PromptResult = ed.GetString(jn) 'Enter the job type Dim jt As New PromptStringOptions(vbLf & "Enter the Job Type:") jt.AllowSpaces = True Dim jtr As PromptResult = ed.GetString(jt) 'Enter the county Dim co As New PromptStringOptions(vbLf & "Enter the Name of County:") co.AllowSpaces = True Dim cor As PromptResult = ed.GetString(co) 'Enter the township Dim twp As New PromptStringOptions(vbLf & "Enter the Name of Municipality:") twp.AllowSpaces = True Dim twpr As PromptResult = ed.GetString(twp) 'Enter the owner / developer Dim owd As New PromptStringOptions(vbLf & "Enter the Name of Owner / Developer:") owd.AllowSpaces = True Dim owdr As PromptResult = ed.GetString(owd) 'Enter the town Dim tn As New PromptStringOptions(vbLf & "Enter the Name of Town:") tn.AllowSpaces = True Dim tnr As PromptResult = ed.GetString(tn) 'Enter the street Dim str As New PromptStringOptions(vbLf & "Enter the Name of Street:") str.AllowSpaces = True Dim strr As PromptResult = ed.GetString(str) Dim sss As AcSmSheet = New AcSmSheet For i As Integer = 1 To nos ss.AddNewSheet(name:="", desc:="") Next 'Unlocks the database ssdb.UnlockDb(ssdb) 'Closes the database ssm.Close(ssdb) End Sub End Class
Yes, I guess I didn't look close enough, at a quick glance I thought nos stood for number of sheets and was an integer. It should be nor.Value.
But before you try to access the value, you should check nor.Status first to make sure the user didn't cancel.
For what it's worth, you are asking for enough user input there that I would probably create a form with textboxes on it to collect the information.
There appears to be zero documentation of the AcSmComponents library, and in my own code I have only read File/Layout lists from sheet sets for use in several Batch Processing functions that I have, so I can't really be of any help on the issue of creating sheets.
My best stab at it with the limited information in front of me, and zero testing, is that you probably aren't supposed to just addnewsheet.
Maybe something like this, but I could be way off.
Dim lyt As New AcSmAcDbLayoutReference lyt.SetFileName(filename) lyt.SetName("Layout1") Dim newsht As AcSmSheet = ss.ImportSheet(lyt) newsht.SetDesc("Description") 'more properties on newsht object
Thanks that infromation has helped
to get nor.value to work I had to change the result to promptintegerresult rather then promptresult
somehow I missed seeing promtpintegerresult the first time through
anyhow adding a sheet is still just beyond my reach and when running the code I get this error:
System.Runtime.InteropServices.COMException (0x80040203): A syntax error occurred trying to evaluate a query string (Exception from HRESULT: 0x80040203) at ACSMCOMPONENTS18Lib.AcSmSheetSetClass.AddNewSheet(String name, String desc) at PlanSetup.Class1.plansetup() in C:\Users\bkenyon\Documents\Visual Studio 2008\Projects\PlanSetup\PlanSetup\Class1.vb:line 34 at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction) at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction) at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction) at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()
below is the code that I have currently, I think I may be missing something with an initnew somewhere:
code snippet
'Enter the number of sheets Dim nos As New PromptIntegerOptions(vbLf & "Enter the Number of Sheets:") Dim nor As PromptIntegerResult = ed.GetInteger(nos) For i As Integer = 1 To nor.Value ss.AddNewSheet(name:="Sheet1", desc:="Cover Sheet") Next
I tested this by using a prompt so I know that the for section works properly
Heard you guys might be looking for documentation and guidance on using the Sheet Set Object API. Here are some that might be useful:
1. AutoCAD 2012 User's Guide - Work with Sheets in a Sheet Set:
Online: Link
2. AutoCAD 2012 - Sheet Set Objects Reference:
Online: Link
3. Autodesk University: CP215-2 Filling the Gaps in the Sheet Set Manager:
Pdf: Download
Video: Link
4. Autodesk University: CP318-4 Taking a Look at the Sheet Set Object With VB.NET:
Online: Link
5. Autodesk University: CP15-1 Taking a Look at the Sheet Set Object:
Pdf: Download
6. Populating a tree view inside AutoCAD with sheet set data using .NET:
Online: Link
7. Populating a tree view inside AutoCAD with sheet set data using .NET - Part 2:
Online: Link
Number 4 was easily the best for me. You have to join Autodesk University but don't worry it's free!
Hope this helps somewhat.
Art.
Sorry for the dealy in posting, but I have been busy lately.
Thanks for the information and I did not get a chance to look at all of them, but I did look at number 4 and it shed some light on the issue I am having.
I have not had a chance to redo the code yet, but I have download the sample code that went with that screencast and I should be able to get what I need from there.
I did notice that one thing that I need to do is get the path of where the sheet set is saved, and also set a default dwt file of rhte sheet set that is created.
another thing that was missing was I noticed in the code that after the addnewsheet was a line that had insertcomponent which from the looks of it needs to be added in order for the sheet to be in the sheet set.
again thanks the information is extremely helpful. I will post the new code once I have a chance to get it changed and tested.
ok, so revised the code, but still get an error when running it not sure what I am missing.
I took the code from the sample that you can download from the one screencast thing to see if that is what I was missing, but for some reason it does not like anything that I put in for the name and description of the sheet to be added.
Error:
System.Runtime.InteropServices.COMException (0x80040203): A syntax error occurred trying to evaluate a query string (Exception from HRESULT: 0x80040203) at ACSMCOMPONENTS18Lib.AcSmSheetSetClass.AddNewSheet(String name, String desc) at PlanSetup.Class1.AddSheet(IAcSmComponent component
Code:
Imports Autodesk.AutoCAD.Runtime Imports ACSMCOMPONENTS18Lib Imports Autodesk.AutoCAD.Windows Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.ApplicationServices Public Class Class1 'Specifies the command to use <CommandMethod("psetup")> _ Public Sub plansetup() 'Get a reference to the Sheet Set Manager object Dim ssm As New AcSmSheetSetMgr 'Selects the save location of the sheet set Dim sfd As New SaveFileDialog(title:="Save Location", defaultName:="", dialogName:="Save Location", extension:="dst", flags:=SaveFileDialog.SaveFileDialogFlags.NoFtpSites) sfd.ShowDialog() 'Create a new sheet set file Dim ssdb As AcSmDatabase ssdb = ssm.CreateDatabase(sfd.Filename, "", True) 'Locks the database ssdb.LockDb(ssdb) Dim sss As AcSmSheetSet sss = ssdb.GetSheetSet AddSheet(ssdb) 'Unlocks the database ssdb.UnlockDb(ssdb) 'Closes the database ssm.Close(ssdb) End Sub ' Used to add a sheet to a sheet set or subset ' Note: This function is dependent on a Default Template and Storage location ' being set for the sheet set or subset. Private Function AddSheet(ByVal component As IAcSmComponent) As AcSmSheet Dim sheet As AcSmSheet sheet = component.GetDatabase().GetSheetSet().AddNewSheet(name:="Sheet1", _ desc:="Description") ' Add the sheet as the first one in the sheet set component.GetDatabase().GetSheetSet().InsertComponent(sheet, Nothing) ' Set the number and title of the sheet sheet.SetNumber(num:="01") sheet.SetTitle(title:="Title") AddSheet = sheet End Function End Class
I see the problem.
Before trying to add any new sheets, you need to specify the directory where new sheet drawings will be placed, as well as the template file and its layout name that the sheet will be based on.
Place the following code between the following lines:
--------------------------------------------------------------------------------------------------------
sss = ssdb.GetSheetSet
' Set new sheet directory location.
Dim fileRef As IAcSmFileReference = sss.GetNewSheetLocation()
fileRef.SetFileName("E:\Junk")
sss.SetNewSheetLocation(fileRef)
' Set new sheet template dwt file and layout name.
Dim layRef As AcSmAcDbLayoutReference = sss.GetDefDwtLayout()
layRef.SetFileName("E:\Junk\Template.dwt")
layRef.SetName("Layout1")
sss.SetDefDwtLayout(layRef)
AddSheet(ssdb)
--------------------------------------------------------------------------------------------------------
Obviously the directory, file and layout paths will vary for you, and you will need to place a template file to do this.
Rather than create dst files from scratch, perhaps it might be easier for you to setup an empty sheet set dst file with all of the typical properties already set, and then use this dst file as a template. You can then programatically add anything that you want to change as follows:
- Create new AcSmDatabase using CreateDatabase(), same as your example;
- Then use AcSmDatabase.LoadFromFile() and specify your dst template file;
- Lock the database;
- Make any changes you want;
- Unlock the database, specifying the bCommit parameter true to save;
Note: The LoadFromFile() method "copies" the data from the default dst file into your AcSmDatabase object, so that when you save it using Unlock() with bCommit set true, the data will be written to the dst file you specified in CreateDatabase().
Hope this helps - Art
Ok, yes, I also found that coding in the sample that I got from the screencast you suggested.
I think I have everything working and now I just need to work out a couple small things to make it perfect.
I will post the code that I have below here. One thing that I noticed is that when I hadd sheets to the sheet set for example I create a sheet set with 2 sheets in it, everything will come up and work and the sheets will be added however I have created a dialog box that comes up and asks for information (works fine), but the first sheet that I put in will be listed below the second(e.g. I want sheet1, sheet2 but it lists as sheet2, sheet1) is there a way to change the order of the sheets so that if you add 4 sheets the dialog box I created will appear 4 times, once for each sheet.
so when the dialog box appears if I add the sheets in backwards it will come out as I want, but I want to add them in order which means the sheet set will have them in backwards.
also the other issue that I seen is that it did not add the custom proerty Total Sheets to the sheet set for some reason and I am not sure why, other then it was not a text value.
thanks for all the help.
Code:
Imports Autodesk.AutoCAD.Runtime Imports ACSMCOMPONENTS18Lib Imports Autodesk.AutoCAD.Windows Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.ApplicationServices Public Class Class1 'Specifies the command to use <CommandMethod("psetup")> _ Public Sub plansetup() 'Get a reference to the Sheet Set Manager object Dim ssm As New AcSmSheetSetMgr 'Selects the save location of the sheet set Dim sfd As New SaveFileDialog(title:="Save Location", defaultName:="", dialogName:="Save Location", extension:="dst", flags:=SaveFileDialog.SaveFileDialogFlags.NoFtpSites) sfd.ShowDialog() 'Create a new sheet set file Dim ssdb As AcSmDatabase ssdb = ssm.CreateDatabase(sfd.Filename, "", True) Dim info As SheetSetInfo = New SheetSetInfo info.ShowDialog() Dim ssf As String ssf = Mid(ssdb.GetFileName, 1, InStrRev(ssdb.GetFileName, "\")) 'Locks the database ssdb.LockDb(ssdb) SetSheetSetDefaults(ssdb, sfd.Filename, "Description", ssf, "C:\Users\bkenyon\Documents\lrgsht1a.dwt", "01 INDEX PLAN") 'Get the sheet set Dim sss As AcSmSheetSet sss = ssdb.GetSheetSet 'Set Custom Properties of the sheet set SetCustomProperty(sss, "Author", info.AuthorTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "County", info.CountyTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Job Date", info.JobDateTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Job Name", info.JobNameTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Job Number", info.JobNumberTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Job Type", info.JobTypeTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Owner / Developer", info.OwnerTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Street", info.StreetTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Total Sheets", info.TotalSheetNum.Value, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Town", info.TownTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Township", info.MunicipalityTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) 'Adds sheets to the sheet set Dim sheetinfo As SheetProps = New SheetProps For i As Integer = 1 To info.TotalSheetNum.Value sheetinfo.ShowDialog() AddSheet(ssdb, sheetinfo.SheetName.Text, sheetinfo.SheetDesc.Text, sheetinfo.SheetNum.Text, sheetinfo.SheetName.Text) Next 'Unlocks the database ssdb.UnlockDb(ssdb) 'Closes the database ssm.Close(ssdb) End Sub ' Used to add a sheet to a sheet set or subset ' Note: This function is dependent on a Default Template and Storage location ' being set for the sheet set or subset. Private Function AddSheet(ByVal component As IAcSmComponent, ByVal name As String, ByVal desc As String, ByVal number As String, ByVal title As String) As AcSmSheet Dim sheet As AcSmSheet sheet = component.GetDatabase().GetSheetSet().AddNewSheet(name, _ desc) ' Add the sheet as the first one in the sheet set component.GetDatabase().GetSheetSet().InsertComponent(sheet, Nothing) ' Set the number and title of the sheet sheet.SetNumber(number) sheet.SetTitle(title) AddSheet = sheet End Function ' Set the default properties of a sheet set Private Sub SetSheetSetDefaults(ByVal sheetSetDatabase As AcSmDatabase, _ ByVal name As String, _ ByVal description As String, _ Optional ByVal newSheetLocation As String = "", _ Optional ByVal newSheetDWTLocation As String = "", _ Optional ByVal newSheetDWTLayout As String = "", _ Optional ByVal promptForDWT As Boolean = False) ' Set the Name and Description for the sheet set sheetSetDatabase.GetSheetSet().SetName(name) sheetSetDatabase.GetSheetSet().SetDesc(description) ' Check to see if a Storage Location was provided If newSheetLocation <> "" Then ' Get the folder the sheet set is stored in Dim sheetSetFolder As String sheetSetFolder = Mid(sheetSetDatabase.GetFileName(), 1, _ InStrRev(sheetSetDatabase.GetFileName(), "\")) ' Create a reference to a File Reference object Dim fileReference As IAcSmFileReference fileReference = sheetSetDatabase.GetSheetSet().GetNewSheetLocation() ' Set the default storage location based on the location of the sheet set fileReference.SetFileName(sheetSetFolder) ' Set the new Sheet location for the sheet set sheetSetDatabase.GetSheetSet().SetNewSheetLocation(fileReference) End If ' Check to see if a Template was provided If newSheetDWTLocation <> "" Then ' Set the Default Template for the sheet set Dim layoutReference As AcSmAcDbLayoutReference layoutReference = sheetSetDatabase.GetSheetSet().GetDefDwtLayout() ' Set the template location and name of the layout ' for the Layout Reference object layoutReference.SetFileName(newSheetDWTLocation) layoutReference.SetName(newSheetDWTLayout) ' Set the Layout Reference for the sheet set sheetSetDatabase.GetSheetSet().SetDefDwtLayout(layoutReference) End If ' Set the Prompt for Template option of the subset sheetSetDatabase.GetSheetSet().SetPromptForDwt(promptForDWT) End Sub ' Set/create a custom sheet or sheet set property Private Sub SetCustomProperty(ByVal owner As IAcSmPersist, _ ByVal propertyName As String, _ ByVal propertyValue As Object, _ ByVal sheetSetFlag As PropertyFlags) ' Create a reference to the Custom Property Bag Dim customPropertyBag As AcSmCustomPropertyBag ' Create a reference to a Custom Property Value Dim customPropertyValue As AcSmCustomPropertyValue = New AcSmCustomPropertyValue() If owner.GetTypeName() = "AcSmSheet" Then Dim sheet As AcSmSheet = owner customPropertyBag = sheet.GetCustomPropertyBag() customPropertyValue.InitNew(sheet) Else Dim sheetSet As AcSmSheetSet = owner customPropertyBag = sheetSet.GetCustomPropertyBag() customPropertyValue.InitNew(sheetSet) End If ' Set the flag for the property customPropertyValue.SetFlags(sheetSetFlag) ' Set the value for the property customPropertyValue.SetValue(propertyValue) ' Create the property customPropertyBag.SetProperty(propertyName, customPropertyValue) End Sub End Class
ok, so I have figured out the order thing.
I changed the insertcomponent to insertcomponentafter which fixes the order of the sheets that I was having issues with.
also I added the tostring for the total sheets custom property whcih added that to the sheet set.
another issue I forgot to mention is:
Is there a way to have the first sheet use a dwt then the other sheets use a different dwt file?
This is how I understand the sheet set manager to work with locations and templates...
When you add a new sheet, the sheet set manager will:
So if you add a new sheet into the root sheet-set it will be based on the root sheet-set properties, but if you add a new sheet into a subset it will be based on the sub-set properties. Also note that when you add a new subset, by default it will copy the properties from the parent - i.e. from the sheet-set (or subset in the case of a nested subset).
So to answer your question... I'd say no you can't specify a different template for the first sheet.
I'm not sure exactly what you are trying to achieve with the first sheet, but here are some options I can think of:
1. For the sheet-set or subset, you can specify the "Prompt for Template" property to be "Yes". This will mean that when the user adds a sheet, AutoCAD will prompt you with a dialog to select a template and layout. I haven't tested it, but my guess is that adding a sheet programatically would ignore this property anyways.
2. You can import a dwg (not a dwt) as the first sheet. Unlike adding a new sheet, this won't actually create a dwg file so it may not suit your purposes. Refer to the ImportASheet method for a sample of how to do this programatically.
3. You can create a seperate subset for the first sheet (with a different template assigned).
4. If I was doing this programatically:- I would set the template file, then add the first sheet, then change the template file for all subsequent sheets added.
Hope this helps.
Art
yes, that helps me understand a little more.
The way I have it setup is that when you run the command a dialog shows and you put in your information including how many sheets you want in the sheet set.
based on that number it will then prompt you for a number, name and description for each sheet, so if you specified you want 4 sheets that dialog would show four times.
The reason that I want to change templates is that we have one for our 1st sheet (cover sheet) of plans that we do and then we have another template we use for all the other sheets. This is not a major thing, but would be nice to do to save some time deleting things from the sheets 2 and on.
I may seem very ambishous with this, but I am also trying to set xreferences to all the sheets. I can post the code if needed. I have it worked out that when each sheet is added it will open it, then I want to add the xreferences based on dwgs selected before then close and save the dwg. I think the only thing that I have not gotten figured out is how to set the newly opened dwg to be the active one.
again thanks for all your help.
Everything with the sheet set command is now working how I would like it.
below is the resulting code:
Imports Autodesk.AutoCAD.Runtime Imports ACSMCOMPONENTS18Lib Imports Autodesk.AutoCAD.Windows Imports Autodesk.AutoCAD.EditorInput Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.Interop Imports Autodesk.AutoCAD.Geometry Public Class Class1 'Specifies the command to use <CommandMethod("psetup")> _ Public Sub plansetup() Dim doc As DocumentCollection = Application.DocumentManager Dim db As New Database(False, False) 'Get a reference to the Sheet Set Manager object Dim ssm As New AcSmSheetSetMgr 'Selects the save location of the sheet set Dim sfd As New SaveFileDialog(title:="Save Location", defaultName:="", dialogName:="Save Location", extension:="dst", flags:=SaveFileDialog.SaveFileDialogFlags.NoFtpSites) sfd.ShowDialog() 'Create a new sheet set file Dim ssdb As AcSmDatabase ssdb = ssm.CreateDatabase(sfd.Filename, "", True) Dim info As SheetSetInfo = New SheetSetInfo info.ShowDialog() Dim ssf As String ssf = Mid(ssdb.GetFileName, 1, InStrRev(ssdb.GetFileName, "\")) 'Locks the database ssdb.LockDb(ssdb) 'Get the sheet set Dim sss As AcSmSheetSet sss = ssdb.GetSheetSet 'Set Custom Properties of the sheet set SetCustomProperty(sss, "Author", info.AuthorTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "County", info.CountyTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Job Date", info.JobDateTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Job Name", info.JobNameTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Job Number", info.JobNumberTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Job Type", info.JobTypeTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Owner / Developer", info.OwnerTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Street", info.StreetTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Total Sheets", info.TotalSheetNum.Value.ToString, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Town", info.TownTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) SetCustomProperty(sss, "Township", info.MunicipalityTxt.Text, PropertyFlags.CUSTOM_SHEETSET_PROP) Dim efd As New OpenFileDialog(title:="Existing Xref File", defaultName:="", dialogName:="Select Existing Xref", extension:="dwg", flags:=OpenFileDialog.OpenFileDialogFlags.NoFtpSites) Dim pfd As New OpenFileDialog(title:="Proposed Xref File", defaultName:="", dialogName:="Select Proposed Xref", extension:="dwg", flags:=OpenFileDialog.OpenFileDialogFlags.NoFtpSites) Dim xrefd As New Xrefdia xrefd.ShowDialog() Dim sheetinfo As SheetProps = New SheetProps If xrefd.DialogResult = Windows.Forms.DialogResult.Yes Then efd.ShowDialog() pfd.ShowDialog() For i As Integer = 1 To info.TotalSheetNum.Value sheetinfo.ShowDialog() If sheetinfo.SheetNum.Text = "1" Then SetSheetSetDefaults(ssdb, sfd.Filename, "Description", ssf, "C:\Users\Barclay\Documents\lrgsht1a.dwt", "01 INDEX PLAN") Else If sheetinfo.SheetNum.Text = "CS-01" Then SetSheetSetDefaults(ssdb, sfd.Filename, "Description", ssf, "C:\Users\Barclay\Documents\lrgsht1a.dwt", "01 INDEX PLAN") Else SetSheetSetDefaults(ssdb, sfd.Filename, "Description", ssf, "C:\Users\Barclay\Documents\lrgsht2.dwt", "01 INDEX PLAN") End If End If AddSheet(ssdb, sheetinfo.SheetName.Text, sheetinfo.SheetDesc.Text, sheetinfo.SheetNum.Text, sheetinfo.SheetName.Text) db.ReadDwgFile(ssf & sheetinfo.SheetName.Text & ".dwg", FileOpenMode.OpenForReadAndAllShare, False, "") Dim xrefid As ObjectId = db.OverlayXref(efd.Filename, efd.Filename) Dim xrefid2 As ObjectId = db.OverlayXref(pfd.Filename, pfd.Filename) Using trans As Transaction = db.TransactionManager.StartTransaction() Dim bt As BlockTable = TryCast(db.BlockTableId.GetObject(OpenMode.ForRead), BlockTable) Dim btr As BlockTableRecord = TryCast(bt(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite), BlockTableRecord) Dim bref As New BlockReference(Point3d.Origin, xrefid) Dim bref2 As New BlockReference(Point3d.Origin, xrefid2) btr.AppendEntity(bref) btr.AppendEntity(bref2) trans.AddNewlyCreatedDBObject(bref, True) trans.AddNewlyCreatedDBObject(bref2, True) trans.Commit() End Using db.SaveAs(ssf & sheetinfo.SheetName.Text & ".dwg", DwgVersion.Current) db.CloseInput(True) db.Dispose() Next Else For i As Integer = 1 To info.TotalSheetNum.Value sheetinfo.ShowDialog() If sheetinfo.SheetNum.Text = "1" Then SetSheetSetDefaults(ssdb, sfd.Filename, "Description", ssf, "C:\Users\Barclay\Documents\lrgsht1a.dwt", "01 INDEX PLAN") Else If sheetinfo.SheetNum.Text = "CS-01" Then SetSheetSetDefaults(ssdb, sfd.Filename, "Description", ssf, "C:\Users\Barclay\Documents\lrgsht1a.dwt", "01 INDEX PLAN") Else SetSheetSetDefaults(ssdb, sfd.Filename, "Description", ssf, "C:\Users\Barclay\Documents\lrgsht2.dwt", "01 INDEX PLAN") End If End If AddSheet(ssdb, sheetinfo.SheetName.Text, sheetinfo.SheetDesc.Text, sheetinfo.SheetNum.Text, sheetinfo.SheetName.Text) Next End If 'Unlocks the database ssdb.UnlockDb(ssdb) 'Closes the database ssm.Close(ssdb) End Sub ' Used to add a sheet to a sheet set ' Note: This function is dependent on a Default Template and Storage location ' being set for the sheet set Private Function AddSheet(ByVal component As IAcSmComponent, ByVal name As String, ByVal desc As String, ByVal number As String, ByVal title As String) As AcSmSheet Dim sheet As AcSmSheet sheet = component.GetDatabase().GetSheetSet().AddNewSheet(name, _ desc) ' Add the sheet as the first one in the sheet set component.GetDatabase().GetSheetSet().InsertComponentAfter(sheet, Nothing) ' Set the number and title of the sheet sheet.SetNumber(number) sheet.SetTitle(title) AddSheet = sheet End Function ' Set the default properties of a sheet set Private Sub SetSheetSetDefaults(ByVal sheetSetDatabase As AcSmDatabase, _ ByVal name As String, _ ByVal description As String, _ Optional ByVal newSheetLocation As String = "", _ Optional ByVal newSheetDWTLocation As String = "", _ Optional ByVal newSheetDWTLayout As String = "", _ Optional ByVal promptForDWT As Boolean = False) ' Set the Name and Description for the sheet set sheetSetDatabase.GetSheetSet().SetName(name) sheetSetDatabase.GetSheetSet().SetDesc(description) ' Check to see if a Storage Location was provided If newSheetLocation <> "" Then ' Get the folder the sheet set is stored in Dim sheetSetFolder As String sheetSetFolder = Mid(sheetSetDatabase.GetFileName(), 1, _ InStrRev(sheetSetDatabase.GetFileName(), "\")) ' Create a reference to a File Reference object Dim fileReference As IAcSmFileReference fileReference = sheetSetDatabase.GetSheetSet().GetNewSheetLocation() ' Set the default storage location based on the location of the sheet set fileReference.SetFileName(sheetSetFolder) ' Set the new Sheet location for the sheet set sheetSetDatabase.GetSheetSet().SetNewSheetLocation(fileReference) End If ' Check to see if a Template was provided If newSheetDWTLocation <> "" Then ' Set the Default Template for the sheet set Dim layoutReference As AcSmAcDbLayoutReference layoutReference = sheetSetDatabase.GetSheetSet().GetDefDwtLayout() ' Set the template location and name of the layout ' for the Layout Reference object layoutReference.SetFileName(newSheetDWTLocation) layoutReference.SetName(newSheetDWTLayout) ' Set the Layout Reference for the sheet set sheetSetDatabase.GetSheetSet().SetDefDwtLayout(layoutReference) End If ' Set the Prompt for Template option of the subset sheetSetDatabase.GetSheetSet().SetPromptForDwt(promptForDWT) End Sub ' Set/create a custom sheet or sheet set property Private Sub SetCustomProperty(ByVal owner As IAcSmPersist, _ ByVal propertyName As String, _ ByVal propertyValue As Object, _ ByVal sheetSetFlag As PropertyFlags) ' Create a reference to the Custom Property Bag Dim customPropertyBag As AcSmCustomPropertyBag ' Create a reference to a Custom Property Value Dim customPropertyValue As AcSmCustomPropertyValue = New AcSmCustomPropertyValue() If owner.GetTypeName() = "AcSmSheet" Then Dim sheet As AcSmSheet = owner customPropertyBag = sheet.GetCustomPropertyBag() customPropertyValue.InitNew(sheet) Else Dim sheetSet As AcSmSheetSet = owner customPropertyBag = sheetSet.GetCustomPropertyBag() customPropertyValue.InitNew(sheetSet) End If ' Set the flag for the property customPropertyValue.SetFlags(sheetSetFlag) ' Set the value for the property customPropertyValue.SetValue(propertyValue) ' Create the property customPropertyBag.SetProperty(propertyName, customPropertyValue) End Sub End Class
Can't find what you're looking for? Ask the community or share your knowledge.