Replace SketchImage

Replace SketchImage

Josh_Hunt
Advocate Advocate
1,003 Views
4 Replies
Message 1 of 5

Replace SketchImage

Josh_Hunt
Advocate
Advocate

GOAL: replace the SketchImage.Image inside a sketch using the path to the new file (PNG, BMP, GIF, JPG).

IDEALLY: I'd like to update the 'embedded' ReferencedOLEFileDescriptor  but I do not see how to match that to the SketchImage. I also do not see a way to update the ReferencedOLEFileDescriptor. Am I wrong? 

I would also accept being able to update the SketchImage.Image (as IPictureDisp) but that is read-only.

LESS IDEALLY: I am currently trying to place a new sketch image >> move it into the same position, rotation, and size >> correct the Decal Feature definition > correct the assembly joint (that uses the sketchimage) 2 levels up.

 

CLARIFY 5/31/2022: I see now it was not clear above that my scenario is an 'embedded' Image so I cannot update or overwrite a file.

Josh Hunt
0 Likes
Accepted solutions (1)
1,004 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Josh_Hunt.  I wend though something similar to this in another post last year.  Basically, it seems like if the image is not linked to a file, you can't just 'replace' it in the traditional sense.  You have to capture the 'Position' of the current image, then delete it, then add the other image using that same position.  However, this is definitely not ideal, because this does not account for size/scale/rotation/mirror factors.  You can attempt to record more aspects of the original image before deleting it, like Name, Width, Height, Transparent, Visible, or even Boundary (the four construction lines around it), and attempt to re-set those same values to the new image after you Add it, but that still doesn't account for rotation or mirror effects, and what if the new image does not have the same Height/Width ratio...you don't want to squish it by trying to set it to the previous image's size.

 

PS:  You can attempt to 'prepare' all alternative images ahead of time, to make sure they are all the same size & ratio, to help eliminate some of that.  If you want to get really detailed, you could probably also record what you had to do, as far as 'Rotate Left or Right x # of times', MirrorVertical or MirrorHorizontal, when you place the image, to the AttributeSet of Either the main Sketch object, or the SketchImage object itself (create multiple Attributes within the set with logical names and values you will understand).  If done in the SketchImage though, keep in mind that they will be lost when you delete it, so you would have to include the process of creating those Attributes into your Replace routine.  That's a lot of work though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

Josh_Hunt
Advocate
Advocate

Thank you,  @WCrihfield that is exactly what I am currently coding. 😓  You mentioned everything I have considered. However I am able to assume the rotate or mirror features were not used.

 

I've had to build A LOT of functions to handle getting Top/Bottom/Left/Right sketch lines and corner points (and I still think my methods would be wrong if the image was perfectly square). Name, Width, Height, Transparent, Visible are simple. I've decided to match the new width to the existing and just log when the height/width ratio differs.

 

This would be MUCH easier if the native API had calls to Top/Bottom/Left/Right sketch lines and corner sketch points. Also a SketchImage.Transform as Matrix2d would have saved me 1-2 days of work.

Josh Hunt
Message 4 of 5

phlyx
Collaborator
Collaborator

Just throwing out a work-around that worked for me.  With Inventor closed I located the JPG that was used in the sketch to make a decal.  I renamed the original image file to something else and then I took the new image file (the same size as the original one) and renamed it the name of the original file.  Then when I opened the model, the decal pulled the new image file.  Tah-dah!  A little prehistoric but ya know, it works!

Message 5 of 5

Josh_Hunt
Advocate
Advocate
@phlyx I see now it was not clear above that my scenario is an 'embedded' Image so I cannot update or overwrite a file.
Josh Hunt
0 Likes