I need to create draft for Part files through vb.net.
But the view type is not fixed.
When doing it manually, I select the Custom View and see if cut portion is in the front.
But how to this programatically?
Right now I am trying using the below code:
For iCnt As Integer = 1 To 30
objDrawingViews = objSheet.DrawingViews
objDrawingView = objDrawingViews.AddPartView(objModelLink, iCnt, 0.25, 0.28, 0.18, 0)
If objDrawingView.IsCut = False Then
But I am getting COM Exception
"Object is not connected to server (Exception from HRESULT: 0x800401FD (CO_E_OBJNOTCONNECTED))".
Is this the right way? if not what is the right method.
Also consider sending
objDrawingViews = objSheet.DrawingViews
outside the loop - before the loop starts - this should speed up the execution a little bit.
The dot between objSheet and DrawingViews has to resolve the property, so more dots means slower execution and a dot inside a loop means even slower execution overall.
Your comment "When doing it manually, I select the Custom View and see if cut portion is in the front."
Can you kindly clarify on "cut portion is in front" - I want to understand how the part looks like and what is meant by cut, where and how it is taken and using which command.
An image of a part with a cut or a simple Solid Edge part attached to this post would be useful.
Thanks in advance.
Thanks for the sugestion.
I am not getting the exception now. But it is not checking for the Cut Part.
As requested by you I am attaching images of Cut Part Behind and Cut Part Front and also what I mean about Cut Part.
Please let me know if there are any APIs which checks for Cut Parts.
You can try looping through the DVLines collection of the view after creation and check the EdgeType against GraphicMemberEdgeTypeConstants if one of them helps to determine if the view has hidden lines.
Looping through the DVLines collection doesn't work.
I just have to check out of top,right,left,front,bottom,back views which view shows cut portion at the front.
I don't think a general solution would be possible.
Try always create the part in a specific orientation such that the cut portion is in front, then always create a front view.
The problem lies in the Delete() method of the drawingView object. Since you've called Delete() once, you cannot use the same variable to place another view and call Delete() again. It triggers the error.
My workaround was to create some auxilary drawingView variables, place the view, check and store some values that I needed and finally delete it. To place the definite view, I used a "default" variable.
In my case it was possible because I have a small number of views(3 or 4), so I only needed 3 or 4 auxiliary variables. In your case, you could reduce your loop to a small number for testing purposes. To deal with the 30 views you would need a array or collection of 30 drawingView objects to always assign the next one.
Please check my code and try to get the idea
SolidEdgeDraft.DrawingView drawingView = null; SolidEdgeDraft.DrawingView auxDrawingView1 = null; auxDrawingView1 = drawingViews.AddAssemblyView(From: modelLink, Orientation: SolidEdgeDraft.ViewOrientationConstants.igLeftView
, Scale: 0.142, x: 0.100, y: 0.23, ViewType: SolidEdgeDraft.AssemblyDrawingViewTypeConstants.se AssemblyDesignedView); VerificarComprimentoAltura(auxDrawingView1, out comprDv1, out altDv1); //Computes smth I need to store
auxDrawingView1.Delete(); // Deletes auxiliary view drawingView = drawingViews.AddAssemblyView(From: modelLink, Orientation: comprDv1 == altDv1 ? SolidEdgeDraft.ViewOrientationConstants.igLeftView : SolidEdgeDraft.ViewOrientationConstants.igFrontVie
w, // Use stored values to place definite view Scale: escala, x: 0.100, y: 0.23, ViewType: SolidEdgeDraft.AssemblyDrawingViewTypeConstants.se AssemblyDesignedView);
Remember: You cannot call Delete() on the same drawinView variable twice(I don't know why).
Please try to adapt this technique to your problem using my tips. If you find a better workaround/solution, please share!
You have a great insight into how the API works and a different approach to tackle problems than many others. I appreciate this.
When I first tried out code posted by Shruthi, I found the ModelLink variable was being set to Nothing after the first run in the loop. So I suggested shifting the ModelLink var inside the For loop which worked.
Can you kindly comment on the approrpiateness of this solution. The Pros and Cons that you see.
Further it would be interesting to know from you if at all it is possible to determine how to place a view on a Draft sheet such that the cut portion of the part appears in front. See the images attached somewhere down in the message. I am also interested in this solution. Thanks.