- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Export picture (PNG) - ilogic - with variable Name
HI all,
i use this Code, for Export Model to PNG Picture:
-----------------------------------------------------------------------------------
Option Explicit On
Dim m_Doc As Inventor.Document
m_Doc = ThisDoc.Document
If m_Doc.DocumentType <> kAssemblyDocumentObject _
And m_Doc.DocumentType <> kPartDocumentObject Then
MessageBox.Show("File is not a model.", "iLogic")
Return 'exit rule
End If
Dim m_Camera As Inventor.Camera
m_Camera = ThisServer.TransientObjects.CreateCamera()
If m_Doc.DocumentType = kPartDocumentObject Then
m_Camera.SceneObject = DirectCast(m_Doc, PartDocument).ComponentDefinition
Else
m_Camera.SceneObject = DirectCast(m_Doc, AssemblyDocument).ComponentDefinition
End If
'm_Camera.Perspective = True
Dim m_TO As Inventor.TransientObjects
m_TO = ThisApplication.TransientObjects
Dim oFileName As String = ThisDoc.FileName(False)
m_Camera.ViewOrientationType = Inventor.ViewOrientationTypeEnum.kIsoTopLeftViewOrientation
m_Camera.Fit
m_Camera.ApplyWithoutTransition
Dim m_PrevMode As DisplayModeEnum
Dim m_Disp3D As Boolean
m_Disp3D = ThisApplication.DisplayOptions.Show3DIndicator
m_PrevMode = ThisApplication.DisplayOptions.NewWindowDisplayMode
ThisApplication.DisplayOptions.NewWindowDisplayMode = DisplayModeEnum.kSHADEDWITHEDGESRendering
ThisApplication.DisplayOptions.Show3DIndicator = False
Try
m_Camera.SaveAsBitmap("C:\Export\" & oFileName & ".png", 2970, 2100, m_TO.CreateColor(255,255,255))
Finally
ThisApplication.DisplayOptions.NewWindowDisplayMode = m_PrevMode
ThisApplication.DisplayOptions.Show3DIndicator = m_Disp3D
End Try
----------------------------------------------------------------------------------
But i have Problem with export more Picture from one Model -> is overwriten. I need edit code and add with variable Name (Name_001 - Name_999).
Please can me help sameone?
TY.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Well.. you have some options..
Do you want to prompt for the file name?
Do you want the file name to just be the models file name + png?
You really can't do a variable as there isn't a method to store the "last known state" that I know of short of exporting to a file and reading that file over each time but thats a bit silly for such a simple task..
Try this..
Option Explicit On
Dim m_Doc As Inventor.Document
m_Doc = ThisDoc.Document
If m_Doc.DocumentType <> kAssemblyDocumentObject _
And m_Doc.DocumentType <> kPartDocumentObject Then
MessageBox.Show("File is not a model.", "iLogic")
Return 'exit rule
End If
Dim m_Camera As Inventor.Camera
m_Camera = ThisServer.TransientObjects.CreateCamera()
If m_Doc.DocumentType = kPartDocumentObject Then
m_Camera.SceneObject = DirectCast(m_Doc, PartDocument).ComponentDefinition
Else
m_Camera.SceneObject = DirectCast(m_Doc, AssemblyDocument).ComponentDefinition
End If
'm_Camera.Perspective = True
Dim m_TO As Inventor.TransientObjects
m_TO = ThisApplication.TransientObjects
Dim oFileName As String = ThisDoc.FileName(False)
m_Camera.ViewOrientationType = Inventor.ViewOrientationTypeEnum.kIsoTopLeftViewOrientation
m_Camera.Fit
m_Camera.ApplyWithoutTransition
Dim m_PrevMode As DisplayModeEnum
Dim m_Disp3D As Boolean
Dim myimagename As String
m_Disp3D = ThisApplication.DisplayOptions.Show3DIndicator
m_PrevMode = ThisApplication.DisplayOptions.NewWindowDisplayMode
ThisApplication.DisplayOptions.NewWindowDisplayMode = DisplayModeEnum.kShadedWithEdgesRendering
ThisApplication.DisplayOptions.Show3DIndicator = False
Try
myimagename = InputBox("Enter a file name", "Image File Name", "Name01.png")
m_Camera.SaveAsBitmap("C:\Export\" & myimagename, 2970, 2100, m_TO.CreateColor(255,255,255))
Finally
ThisApplication.DisplayOptions.NewWindowDisplayMode = m_PrevMode
ThisApplication.DisplayOptions.Show3DIndicator = m_Disp3D
End Try
-------------------------------------------------------------------------------------------
Inventor 2023 - Dell Precision 5570
Did you find this reply helpful ? If so please use the Accept Solution button below.
Maybe buy me a beer through Venmo @mcgyvr1269
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I need only save more screenshots (Image) from different sides, unter Name: Model_001, Model_002, Model_003 - Model_XXX
Model = Part or Assembly that is for me FileName
1-click on ilogic rule = 1 new screen shots with with a suffix _001 - XXX, iLogic itself saves other sreenshots under a new name (verify it free suffix)
Something like here on other forum at STEP file (link is forbidden) :
Option Explicit On
Dim m_Doc As Inventor.Document
m_Doc = ThisDoc.Document
' Start of iLogic code *******************************************
Stepfilename = ThisDoc.PathAndFileName(False)
Counter = 0
FileExists = True
'check to see if the file to be exported already exists
Do While FileExists
' Define name of exported file - note a .stp file extension
' Is currently being used. In this example I am exporting a Step file
CurrentFile = Stepfilename & "_V" & Counter & ".stp"
If Dir(CurrentFile) <> "" Then ' The file does exist
Counter += 1
FileExists = True
Else
SaveAs = MessageBox.Show("Export file as '" & CurrentFile & _
"'?", "Cadline iLogic", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
MessageBoxDefaultButton.Button1)
If SaveAs = vbNo Then
Return
Else ' User says continue
FileExists = False
End If
End If
Loop
' Put your export or 'save as' code in here ***********************
' Get the STEP translator Add-In.
Dim oSTEPTranslator As TranslatorAddIn
oSTEPTranslator = ThisApplication.ApplicationAddIns.ItemById _
("{90AF7F40-0C01-11D5-8E83-0010B541CD80}")
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
If oSTEPTranslator.HasSaveCopyAsOptions(ThisApplication.ActiveDocument _
, oContext, oOptions) Then
oOptions.Value("ApplicationProtocolType") = 3
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
Dim oData As DataMedium
oData = ThisApplication.TransientObjects.CreateDataMedium
' Set export name of STEP file
oData.FileName = CurrentFile
oSTEPTranslator.SaveCopyAs(ThisApplication.ActiveDocument, oContext _
, oOptions, oData)
End If
' End of export code ***********************************************
' Ask user if they want to open the export folder
OpenFolder = MessageBox.Show("Export successful! " & _
"- open containing folder now?", "Cadline iLogic", _
MessageBoxButtons.YesNo, _
MessageBoxIcon.Question,MessageBoxDefaultButton.Button1)
If OpenFolder = vbYes Then
Process.Start("explorer.exe", ThisDoc.Path)
Else ' User says continue
'Return
End If
' End of iLogic code **************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
https://forums.autodesk.com/t5/inventor-customization/transparent-background/m-p/7761624#M80096
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
this no ...
my new functional code:
oView = ThisApplication.ActiveView
Dim originalSchema As String
originalSchema = ThisApplication.ActiveColorScheme.Name
Dim originalBkg As BackgroundTypeEnum
originalBkg = ThisApplication.ColorSchemes.BackgroundType
ThisApplication.ColorSchemes.Item("Prezentace").Activate
ThisApplication.ColorSchemes.BackgroundType = 52737 'kOneColorBackgroundType
Dim originSetOff as Boolean
originSetOff = False
If ThisApplication.DisplayOptions.Show3DIndicator Then
ThisApplication.DisplayOptions.Show3DIndicator = False
originSetOff = True
End If
Dim picName As String = "C:\Export\" + ThisDoc.FileName(False) + Now.toString("-yyMMddHHmmss") 'timestamp
Call oView.SaveAsBitmap(picName & ".png", oView.Width, oView.Height)
If originSetOff Then
ThisApplication.DisplayOptions.Show3DIndicator = True
End If
ThisApplication.ColorSchemes.Item(originalSchema).Activate
ThisApplication.ColorSchemes.BackgroundType = originalBkg
'MsgBox(ThisDoc.PathAndFileName(True) & ".png")