Reply
Solved! Go to solution

Draw (lines, circles...) into DrawingView from the API

Hello guys. This is driving me mad, hope you can help.

 

I'm writing a program which needs to draw some entities (lines) inside a drawing view which holds a solid part. I know how to draw in the sheet itself, but I need to do that INSIDE the view. It's the same operation you can manually do right-clicking on a View and selecting Draw in View.

 

I have no idea how to access those entities manually drawn into the view from the API, since collections such as DVLines2d and so just include geometry derived from the 3d part, no that added manually. I have searched along most DrawingView and ModelMember stuff with no success.

 

Any clue?

 

Much thanks in advance!!!!

17 REPLIES

Re: Draw (lines, circles...) into DrawingView from the API

Hey javigoca,

 

There is no "nice" way to do this AFAIK. What I did in one of my apps was the following:

 

ActiveDrawingView = (DrawingView)ActiveSheet.DrawingViews.Item(1);
ActiveDrawingView.Select();
Application.StartCommand((SolidEdge.Framework.Interop.SolidEdgeCommandConstants)40037);

//Wait until "inside" drawing view
System.Threading.Thread.Sleep(100);

///Your code here...

 

//Close drawing view

Application.StartCommand((SolidEdge.Framework.Interop.SolidEdgeCommandConstants)10231);

//Wait until drawing view is closed
System.Threading.Thread.Sleep(1000);

 

Its not nice, especially the sleeping part, but it worked for me.

Hope it helps...

 

best,

Jonas

Re: Draw (lines, circles...) into DrawingView from the API

Wow, thanks for the fast response.

 

I agree, it's quite ugly, so I will manage drawing directly on the sheet.

 

In fact I had just coded my app in this way (it automates laser template extraction from parts, adding some special marks and measures for beter management), but drawing each part references in its own view was somewhat cleaner and more elegant.

 

This is quite weird since, when using SE directly I always try to draw inside views, avoiding "floating" drawings on the sheet, which furthermore generate conflicts with measures and scale. It's curious to see how the API seems closed to the first solution.

 

Again, many many thanks!

Solution
Solution
Accepted by topic author javigoca
‎08-26-2015 04:32 AM

Re: Draw (lines, circles...) into DrawingView from the API

[ Edited ]

To draw in a DrawingView is much simpler, as each DrawingView has its own Sheet and you just need to draw on that local sheet.

The following code creates a linear dimension between the first two lines it can find in the first DrawingView. Then it draws a circle around the first line:

 

'-----------------------------------------------------
' DFT: Create a dimension in a drawing view in draft
'-----------------------------------------------------
Dim objDoc As DraftDocument = objApp.ActiveDocument
' Get the first drawing view on the active sheet
Dim objSheet As Sheet = objDoc.ActiveSheet
Dim objView As DrawingView = objSheet.DrawingViews.Item(1)
' Get the first two lines in the drawing view
Dim objLine1 As DVLine2d = objView.DVLines2d.Item(1)
Dim objLine2 As DVLine2d = objView.DVLines2d.Item(2)
' Create a length dimension on the first line INSIDE the drawing view
Dim objDims As Dimensions = objView.Sheet.Dimensions
Dim objDim As Dimension = objDims.AddLength(objLine1)
' Create a circle around the first line INSIDE the drawing view
Dim x1, y1, x2, y2 As Double
objLine1.GetStartPoint(x1, y1)
objLine1.GetEndPoint(x2, y2)
Dim objCircles As Circles2d = objView.Sheet.Circles2d
Dim objCirc As Circle2d = objCircles.AddByCenterRadius((x1 + x2) / 2, (y1 + y2) / 2, objLine1.Length / 2)

 

Re: Draw (lines, circles...) into DrawingView from the API

Didn't know that, thanks!

Re: Draw (lines, circles...) into DrawingView from the API

Amazing! I will ty that this weekend.

 

Really, amazing fast response.

 

When reading the (let's be honest, incredibly poor) SDK docs I though that the Sheet property contained a reference for the Sheet in which the View was contained, didn't thought this way.

 

Again, really much thanks again for your help.

 

As a comment, I think siemens would have to pay more atention to the SDK documentation. I'm working on it for 4 months and I'm amazed of the possibilities it offers. However, the lack of a good documentation makes this stuff a very dark matter, full of forum searching and trial-error, with most examples on the docs too simple (nearly silly and useless) outdated or incorrect. Having a good SDK on which to work in a comfortable way is a good selling point for medium-big companies. Having it but with no decent documentation it's the most dumb path!

Re: Draw (lines, circles...) into DrawingView from the API

I agree with you that the SDK documentation could/should be much better, but it has been worse and it is getting better with every release.

 

Jason Newell is making a big effort in getting a lot of "real" sample code out on the Solid Edge Samples site on Codeplex (http://solidedgesamples.codeplex.com/).

You should also look for his Spy for Solid Edge, which should be the nº1 tool for each SE developer to get more insight into the API and how it works!!

Re: Draw (lines, circles...) into DrawingView from the API


freijon wrote:

Hey javigoca,

 

There is no "nice" way to do this AFAIK. What I did in one of my apps was the following:

 

ActiveDrawingView = (DrawingView)ActiveSheet.DrawingViews.Item(1);
ActiveDrawingView.Select();
Application.StartCommand((SolidEdge.Framework.Interop.SolidEdgeCommandConstants)40037);

//Wait until "inside" drawing view
System.Threading.Thread.Sleep(100);

///Your code here...

 

//Close drawing view

Application.StartCommand((SolidEdge.Framework.Interop.SolidEdgeCommandConstants)10231);

//Wait until drawing view is closed
System.Threading.Thread.Sleep(1000);

 

Its not nice, especially the sleeping part, but it worked for me.

Hope it helps...

 

best,

Jonas


Hey Jonas,

 

Am pretty new to Soild Edge Automation and pretty new to any kind of programming as well. Was just browsing through the thread and saw your post. Was wondernig why the System.Threading.Thread.Sleep(100) is required? What is its purpose?

Re: Draw (lines, circles...) into DrawingView from the API

Hey Govind,

 

It's required because it seems like Application.StartCommand(...) is executed asynchronously (the program doesn't wait until the command is finished), but my following code makes only sense when StartCommand has finished. There are certain events you can use, but they are limited and in that case non-existant (afaik).

 

Hope that answered your question

Re: Draw (lines, circles...) into DrawingView from the API

Instead of calling Sleep(), I suggest to use oApp.DoIdle() after each call of oApp.StartCommand().