Add Image on 2D drawing Sheet

Add Image on 2D drawing Sheet

byzkc54
Contributor Contributor
1,008 Views
6 Replies
Message 1 of 7

Add Image on 2D drawing Sheet

byzkc54
Contributor
Contributor

Hello,
I want to automatically add the screenshot taken in the code I wrote below to the technical drawing. Can you help me?


Sub Main()
    Dim oPart As PartDocument
    oPart = ThisApplication.ActiveDocument

    Dim o3dActiveView As Inventor.View
    o3dActiveView = ThisApplication.ActiveView

    Dim oPartNumber As String
    oPartNumber = oPart.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value

    Dim o3DCamera As Camera
    o3DCamera = o3dActiveView.Camera
    o3DCamera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopLeftViewOrientation

    o3DCamera.Apply()
    o3dActiveView.Fit()

    Dim oFolder As String
    oFolder = "C:\Users\byzkc\Desktop\iLogic Deneme Assembly"
    Dim oFileName As String
    oFileName = oFolder & oPartNumber & ".jpeg"

    o3dActiveView.SaveAsBitmap(oFileName & ".jpg", 1300, 1300)

    Dim oDrawingDoc As DrawingDocument
    oDrawingDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, "C:\Users\byzkc\Desktop\iLogic Deneme Assembly\de.idw", True)
    oDrawingDoc.Activate()

    Dim oSheet As Sheet
    oSheet = oDrawingDoc.Sheets.Item(1)

    Dim x1 As Double = 10.2
    Dim y1 As Double = 16.2
    Dim x2 As Double = 20.2
    Dim y2 As Double = 22.2

    Dim width As Double = x2 - x1
    Dim height As Double = y2 - y1

    Dim centerX As Double = x1 + (width / 2)
    Dim centerY As Double = y1 + (height / 2)

    Dim oPoint1 As Point2d
    oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(centerX, centerY)

    Dim oView As DrawingView
    oView = oSheet.DrawingViews.AddBaseView(oPart, oPoint1, 1.1, ViewOrientationTypeEnum.kIsoTopRightViewOrientation, DrawingViewStyleEnum.kShadedDrawingViewStyle)

    Dim scaleFactor As Double = Math.Min((width / oView.Width), (height / oView.Height))
    oView.Scale = scaleFactor

    MsgBox(oPartNumber & " Ekran Görüntüsü Alındı")
	

End Sub
0 Likes
Accepted solutions (1)
1,009 Views
6 Replies
Replies (6)
Message 2 of 7

A.Acheson
Mentor
Mentor

Hi @byzkc54 

I believe the only way to add an image and control its position is to first add it to a sketch symbol then it can be correctly positioned. 

See this post here written in vba.

 

Converted here to ilogic but untested

Sub Main

Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument

Dim oSkSymDef As SketchedSymbolDefinition = oDoc.SketchedSymbolDefinitions.Add("YOUR_SKETCH_SYMBOL_NAME")

'Suggest adding your image at coordinate 0,0. You may like to revise this to suit your application.
Dim oPoint2d As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)

Dim oImgFN As String = "C:\YOURFILENAME.PNG"

Dim oSK As DrawingSketch = Nothing

oSkSymDef.Edit (oSK)
oSK.SketchImages.Add (oImgFN, oPoint2d, False)
oSkSymDef.ExitEdit

Dim oSkSym as SketchedSymbol = oDoc.ActiveSheet.SketchedSymbols.Add (oSkSymDef, oPoint2d)

'Then oSkSym is the object you can manipulate to suit your application.

End Sub

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 7

byzkc54
Contributor
Contributor
I guess I didn't make it. Because I can't add the screenshot I made earlier to the technical drawing letterhead.
0 Likes
Message 4 of 7

A.Acheson
Mentor
Mentor

Can you attach the code your trying? Have you tried to bring image into sketch symbol?

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor

Just a quick glance observation...but within the original code you posted, I think you may be missing a "\" symbol within the full file name of the image file.  I'm guessing it should either be at the end of your oFolder value, or included between your oFolder & oPartNumber variables, when setting the value of the oFileName variable, unless "iLogic Deneme Assembly" is part of he image file's name, and not the folder it is in.

    Dim oFolder As String
    oFolder = "C:\Users\byzkc\Desktop\iLogic Deneme Assembly"
    Dim oFileName As String
    oFileName = oFolder & oPartNumber & ".jpeg"

I don't know if that fixes anything, just pointing it out, in case it helps.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 7

byzkc54
Contributor
Contributor
I draw a part on a solid model and automatically create its technical drawing. I then save a view as a screenshot. I want to add this screenshot I took to the technical drawing I created.
0 Likes
Message 7 of 7

A.Acheson
Mentor
Mentor
Accepted solution

Have you tried adding the image to the symbol as previously suggested? 

Edit:

Here is the updated code. I scaled down your image to fit on the sheet. The image quality is not great so you will need to play with this to see if you can work with it. 

AAcheson_0-1692149194762.png

 

 

 

Sub Main()
    Dim oPart As PartDocument
    oPart = ThisApplication.ActiveDocument

    Dim o3dActiveView As Inventor.View
    o3dActiveView = ThisApplication.ActiveView

    Dim oPartNumber As String
    oPartNumber = oPart.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value

    Dim o3DCamera As Camera
    o3DCamera = o3dActiveView.Camera
    o3DCamera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopLeftViewOrientation

    o3DCamera.Apply()
    o3dActiveView.Fit()

    Dim oFolder As String
    oFolder = ThisDoc.Path
    Dim oFileName As String
    
	oImageFN = oFolder & "\" & oPartNumber & ".jpg"

    o3dActiveView.SaveAsBitmap(oImageFN, 500, 500)

    Dim oDrawingDoc As DrawingDocument
    oDrawingDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject,"C:\Users\aacheson\Desktop\WFH\Samples\1234-1.dwg" , True)
    oDrawingDoc.Activate()

    Dim oSheet As Sheet
    oSheet = oDrawingDoc.Sheets.Item(1)

    Dim x1 As Double = 10.2
    Dim y1 As Double = 16.2
    Dim x2 As Double = 20.2
    Dim y2 As Double = 22.2

    Dim width As Double = x2 - x1
    Dim height As Double = y2 - y1

    Dim centerX As Double = x1 + (width / 2)
    Dim centerY As Double = y1 + (height / 2)

    Dim oPoint1 As Point2d
    oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(centerX, centerY)

    Dim oView As DrawingView
    oView = oSheet.DrawingViews.AddBaseView(oPart, oPoint1, 1.1, ViewOrientationTypeEnum.kIsoTopRightViewOrientation, DrawingViewStyleEnum.kShadedDrawingViewStyle)

    Dim scaleFactor As Double = Math.Min((width / oView.Width), (height / oView.Height))
    oView.Scale = scaleFactor

    MsgBox(oPartNumber & " Ekran Görüntüsü Alındı")
	
	'[ Create image holder.
	Dim oSkSymDef As SketchedSymbolDefinition = oDrawingDoc.SketchedSymbolDefinitions.Add(oPartNumber & " image")

	'Place Image
	Dim x As Double = oSheet.Border.RangeBox.MinPoint.X +25
	Dim y As Double = oSheet.Border.RangeBox.MinPoint.Y +25
	Dim oPoint2d As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(x,y)

	Dim oSK As DrawingSketch = Nothing

	oSkSymDef.Edit (oSK)
	oSK.SketchImages.Add (oImageFN, oPoint2d, False)
	oSkSymDef.ExitEdit

	Dim oSkSym As SketchedSymbol = oDrawingDoc.ActiveSheet.SketchedSymbols.Add(oSkSymDef, oPoint2d)
	']
End Sub

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes