ive started to learn VB so that i can automate some of my drafting tasks. my main project right now is replacing the old sheet style with our fancy new version.
ive spent the last week going through VB tutorials on youtube, trying to grasp the basics.
i certainly am not after a full solution. just help on a good starting place.
im really keen on learning VB and feel somewhat confident that i can look through the code to grasp the basic understanding of what its doing.
Im looking for a snippet of code that can open a specific draft file stored locally.
can anyone help?
I was in a similar position a while back.
I copied some code from others to create a vb macro.
this macro when run while a model file is open, checks for a draft file with the same name in the current Dir. and opens it , or runs the create a new draft from the current model command.
i found that trying to see how others did things was easier that trying to write from scratch.
hope it helps bit,
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim objApp As SolidEdgeFramework.Application = Nothing Dim objRev As RevisionManager.Application = Nothing Dim objRevDft As RevisionManager.Document = Nothing Dim objDocuments As SolidEdgeFramework.Documents = Nothing Dim objDocument As SolidEdgeFramework.SolidEdgeDocument = Nothing Dim objPart As SolidEdgePart.PartDocument = Nothing Dim objdraft As SolidEdgeDraft.DraftDocument = Nothing Dim pathname As String Dim partname As String Dim dftname As String Try objApp = Marshal.GetActiveObject("SolidEdge.Application") objRev = CreateObject("RevisionManager.Application") objDocument = objApp.ActiveDocument
pathname = objDocument.Path ' Edited into code partname = objDocument.FullName objRev.WhereUsedCriteria("*.dft", True) = pathname objRevDft = objRev.FindWhereUsed(partname) If IsNothing(objRevDft) Then Call objApp.StartCommand(CommandID:=39001) Me.Close() Application.DoEvents() End If dftname = objRevDft.FullName Me.Close() objApp.Visible = True objDocuments = objApp.Documents objPart = objDocuments.Open(objRevDft.FullName) Application.DoEvents() Catch ex As Exception Finally If Not (objApp Is Nothing) Then Marshal.ReleaseComObject(objApp) objApp = Nothing End If If Not (objRev Is Nothing) Then Marshal.ReleaseComObject(objRev) objRev = Nothing End If If Not (objRevDft Is Nothing) Then Marshal.ReleaseComObject(objRevDft) objRevDft = Nothing End If If Not (objDocuments Is Nothing) Then Marshal.ReleaseComObject(objDocuments) objDocuments = Nothing End If If Not (objDocument Is Nothing) Then Marshal.ReleaseComObject(objDocument) objDocument = Nothing End If If Not (objPart Is Nothing) Then Marshal.ReleaseComObject(objPart) objPart = Nothing End If If Not (objdraft Is Nothing) Then Marshal.ReleaseComObject(objdraft) objdraft = Nothing End If End Try End Sub
Also a search on google for "solid edge api" brings up a programmers guide, a good place to start.
Any questions fire away - always found this forum happy to help
Added missing line to code to correct mistake shown below..
Is this code tested? I am consistently getting 'Nothing' for objRevDft and it runs the command with ID 39001
I have the draft of the current model in the same directory as the .PAR file.
Have you given a value to the pathname variable?
Maybe in your case could be:
pathname = Path.GetDirectoryName(partname)
Otherwise I think
objPart = objDocuments.Open(objRevDft.FullName)
objdraft = objDocuments.Open(dftname)
Hope it helps.
Héctor Pelayo Izquierdo
Engineering Department, JAE Ingeniería y Desarrollos, S.L.
Solid Edge ST9 MP5 | NX 9
I have been looking for a way to enter the draft file of an open model for sometime. I am excited to use this program. I have tried to make it work but am hardly familar with VB. I am having trouble recognizing:
If someone could help me out that would be awesome!
Thank you in advance.