How create Draft by Quick Sheet from a Part with C# or VB

[ Edited ]

How create a Draft by Quick Sheet from a Part??


Like steps:

  1. I have a part
  2. Create drawing, this template is a Quick Sheet DFT.
  3. Insert part in models views



            Application application = null;
            Documents documents = null;
            AssemblyDocument asDocument = null;
            Occurrences occurrences = null;
            List<string> occurrence = new List<string>();
            SolidEdgeDraft.DraftDocument draftDocument = null;
            SolidEdgeDraft.ModelLinks modelLinks = null;
            SolidEdgeDraft.ModelLink modelLink = null;
            SolidEdgeDraft.Sheet sheet = null;
            SolidEdgeDraft.DrawingViews drawingViews = null;
            SolidEdgeDraft.DrawingView drawingView = null;
            SolidEdgeDraft.ModelMembers modelMembers = null;
            SolidEdgeDraft.ModelMember modelMember = null;

            application = SolidEdgeUtils.Connect(true, true);
            documents = (Documents)application.Documents;
            assDocument = (AssemblyDocument)application.ActiveDocument;
            occurrences = (Occurrences)asDocument.Occurrences;

(...) // occurrence receive the parts of the Main Assembly

foreach (string itemChapa in occurrence)
                draftDocument = documents.Add("SolidEdge.DraftDocument", arquivoTemplate) as SolidEdgeDraft.DraftDocument;

                modelLinks = draftDocument.ModelLinks;

                modelLink = modelLinks.Add(itemChapa);

                sheet = draftDocument.ActiveSheet;

                drawingViews = sheet.DrawingViews;
for (int i = 1; i <= drawingViews.Count; i++) { drawingView = drawingViews.Item(i) as SolidEdgeDraft.DrawingView; modelMembers = drawingView.ModelMembers; modelMember = modelMembers.Item(i); // Here have a problem, I do not know how to insert the part in drawing views. }


Kabir Costa
Industrial Designer

Re: How create Draft by Quick Sheet from a Part with C# or VB

AFAIK, there is no direct API to set the part for all QuickSheet views.

You will need to simulate what SE is doing when dragging and dropping a part file onto the sheet with the quicksheet views:

1) Set the model link in the document

2) Replace each quicksheet view by a part view


As you cannot query the orientation of a quicksheet view (causes E_POINTER exception), you should indicate the view orientation in any way in the quicksheet view, e.g. by setting its ID in the Caption property and saving your own QuickSheet template.

Then you can iterate through all drawing views, get their orientation from the ID you stored in the Caption and finally create a new PartView with the same position, orientation, scale, and drawing view type as the original quicksheet view.

You can then delete the original views.

See my sample code below:

    ' DFT: Create a draft based on a QuickSheet template
    Const SE_INSTALL_PATH As String = "C:\Program Files\Solid Edge ST8"

    ' Create a new draft document
    Dim objDoc As DraftDocument = objApp.Documents.Add("SolidEdge.DraftDocument", SE_INSTALL_PATH & "\Template\MyQuickSheet\metric QS part.dft")
    Dim objMdlLink As ModelLink = objDoc.ModelLinks.Add(SE_INSTALL_PATH & "\Training\Body01.par")
    For Each objView As DrawingView In objDoc.ActiveSheet.DrawingViews
      Dim bIsQuickSheetView As Boolean = (objView.ModelMembers.Count = 0)
      If bIsQuickSheetView Then
        Dim origX, origY As Double
        Dim orient As ViewOrientationConstants = GetOrientFromView(objView)
        objView.GetOrigin(origX, origY)
        Dim newView As DrawingView = objDoc.ActiveSheet.DrawingViews.AddPartView(objMdlLink, orient, objView.ScaleFactor, origX, origY, objView.DrawingViewType)
      End If

Re: How create Draft by Quick Sheet from a Part with C# or VB

There is a method PopulateQuicksheetTemplate () in the DraftDocument object.
This should work. I have no example code, sorry for that.

VS2015, SE ST10

Re: How create Draft by Quick Sheet from a Part with C# or VB

Thank for your answer!

Kabir Costa
Industrial Designer