Cancel
Showing results for 
Search instead for 
Did you mean: 

How to Insert image on a draft ?

Valued Contributor
Valued Contributor

Hi, everyone.

 

I'm inspecting the draft objects(DraftDocument, DrawingView etc) searching for a property or method to insert an image to a draft, like in the picture bellow(selected in pink).

 

I know it's ought to be simple, but I looked at documentation and Solid Edge Spy, and I couldn't find it.

 

Does anybody know the code that does that?

 

Thanks!

 

draft.png

7 REPLIES 7

Re: How to Insert image on a draft ?

Pioneer
Pioneer

I did the opposit, I had to search for an image and had to delete it. Its quite hidden:

 

FrameworkSupport.SmartFrame2d

 

To add a new one, you presumably can use (note the plural):

var image = FrameworkSupport.SmartFrames2d.AddBy2Points(StyleName, x, y);

image.CreateEmbed("C:\image.bmp");

and then modify the options of the SmartFrame2d object.

 

Hope that helps

Re: How to Insert image on a draft ?

Valued Contributor
Valued Contributor

Hi, Freijon. Thanks for your response!

 

I'm having a litle problem with this code. VS complains that an object reference is needed to call the method AddBy2Points as you can see bellow:

Erro1.jpg

 

When I try to create the object it says that I can't create an instance of this abstract class or interface:

Erro2.jpg

It seems not to make sense creating a custom class that supports this interface and implement this method so that I could instanciate an object and call it.

 

Sorry if I'm missing something really silly right under my nose.

 

Any ideas about how I can use the method SmartFrames2d.AddBy2Points() to create a SmartFrame?

 

Re: How to Insert image on a draft ?

Pioneer
Pioneer

Hey Marcio_Lima,

 

Sorry, my code was supposed to be dummy code to explain the situation. What you will have to do is the following (in C# but I'm sure you can translate it yourself):

 

DraftDocument dft = null;
Sheet sheet = null;

SmartFrames2d sfs2d = null;

SmartFrame2d image = null;

 

dft = (DraftDocument)app.ActiveDocument; //"app" is the Application object
sheet = (Sheet)dft.ActiveSheet;

sfs2d = (SmartFrames2d)sheet.SmartFrames2d;

image = (SmartFrame2d)sfs2d.AddBy2Points("", 0.5, 1.0, 1.0, 1.5);

image.CreateEmbed("C:\image.png");

 

Haven't tested the code, but it should work IMO.

 

Re: How to Insert image on a draft ?

Valued Contributor
Valued Contributor

Hello, Frejon

 

Thanks for you code. It really shows the SmartFrame2d, but displaying only the name of the image, as you can see bellow:

Erro3.jpg

I left the Style parameter blank(image = (SolidEdgeFrameworkSupport.SmartFrame2d)sfs2d.AddBy2Points("", 0.0, 0.0, 0.01, 0.3)Smiley Wink

 

I don't know if it's causing the issue. I'm investiganting the SmartFrame2dDefault(s) and SmartFrame2dStyle(s), but wiht no success until now. If I have any news I'll post here.

Re: How to Insert image on a draft ?

Valued Contributor
Valued Contributor

Hey, Freijon!

I finally did it! It's similar to your solution! The sheet class has an image2D object.

 

 

SolidEdgeFrameworkSupport.Images2d imgs = null;
SolidEdgeFrameworkSupport.Image2d img = null;

imgs = sheet.Images2d;
img = imgs.AddImage(true, @"C:\Detail.png");
img.Update();

 success.jpg

Thanks a lot for your help!

Re: How to Insert image on a draft ?

Creator
Creator

Hey Marcio_Lima,

Thanks for you code.

I used your code:

SolidEdgeFrameworkSupport.Images2d imgs = null;

SolidEdgeFrameworkSupport.Image2d img = null;

imgs = sheet.Images2d;

img = imgs.AddImage(true, @"C:\Detail.png");

img.Update();

 

but I get a error message: Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT)).

I don't know if it's causing the issue.

If you are convenient, please help me.

Thanks!

Re: How to Insert image on a draft ?

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

If there is no difference for you, try to embed the image in the draft by using "false" as first parameter.

Trying to link any file of type BMP, PNG, JPG (I did not try more) in ST10 MP6 gives me an "MK_E_INVALIDEXTENSION" exception!