Hello everyone.
I created a code based on the following topic and ChatGPT.
Sub Main() Dim saveName As String Dim oDoc As PartDocument oDoc = ThisApplication.ActiveDocument Dim oActiveView As View oActiveView = ThisApplication.ActiveView Dim oCamera As Camera oCamera = oActiveView.Camera oCamera.ViewOrientationType = kIsoTopRightViewOrientation oCamera.ApplyWithoutTransition ThisApplication.ActiveView.Fit saveName = Left$(oDoc.FullDocumentName, Len(oDoc.FullDocumentName) -4) Dim resolutionX As Integer Dim resolutionY As Integer resolutionX = 350 resolutionY = 270 Call oActiveView.SaveAsBitmap(saveName & ".bmp", resolutionX, resolutionY) End Sub
With this code, I currently have two issues.
I think that's all for now. If I can find solutions to these, I'd like to add the functionality to extract images from tables as well, but that's a job for later, I guess. But if you have any knowledge about this, please share.
Hello everyone.
I created a code based on the following topic and ChatGPT.
Sub Main() Dim saveName As String Dim oDoc As PartDocument oDoc = ThisApplication.ActiveDocument Dim oActiveView As View oActiveView = ThisApplication.ActiveView Dim oCamera As Camera oCamera = oActiveView.Camera oCamera.ViewOrientationType = kIsoTopRightViewOrientation oCamera.ApplyWithoutTransition ThisApplication.ActiveView.Fit saveName = Left$(oDoc.FullDocumentName, Len(oDoc.FullDocumentName) -4) Dim resolutionX As Integer Dim resolutionY As Integer resolutionX = 350 resolutionY = 270 Call oActiveView.SaveAsBitmap(saveName & ".bmp", resolutionX, resolutionY) End Sub
With this code, I currently have two issues.
I think that's all for now. If I can find solutions to these, I'd like to add the functionality to extract images from tables as well, but that's a job for later, I guess. But if you have any knowledge about this, please share.
Hi @ebaras. Why is that exact size so important? If it is super important, then you may have to scale and/or crop the image after capturing it, instead of as you are capturing it. It is usually best to maintain the aspect ratio of the view window's size (View.Height & View.Width) in the output image file, otherwise the output image may get squished in one direction, or both directions, making it not look good. You could also try using the Camera.SaveAsBitmap method, instead of the View.SaveAsBitmap method, but I do not recall if that would make much difference in a situation like that.
Wesley Crihfield
(Not an Autodesk Employee)
Hi @ebaras. Why is that exact size so important? If it is super important, then you may have to scale and/or crop the image after capturing it, instead of as you are capturing it. It is usually best to maintain the aspect ratio of the view window's size (View.Height & View.Width) in the output image file, otherwise the output image may get squished in one direction, or both directions, making it not look good. You could also try using the Camera.SaveAsBitmap method, instead of the View.SaveAsBitmap method, but I do not recall if that would make much difference in a situation like that.
Wesley Crihfield
(Not an Autodesk Employee)
@ebaras wrote:
With this code, I currently have two issues.
- I cannot run this code in the assembly file. How can we adjust the code to work in assembly files as well?
- The quality of the images I'm getting as output is poor. It's important for the output images to have dimensions of 350x270 px, but they look bad at this size. Can we fix this?
Hi @ebaras,
I'm answering your question about first point ("code in the assembly"), I did a cleanup of your original code taking care about @WCrihfield suggestions (this doesn't change anything about what already said @WCrihfield on image resolution).
Dim oCamera As Camera = ThisApplication.ActiveView.Camera
oCamera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation
oCamera.ApplyWithoutTransition()
oCamera.Fit()
Dim resolutionX As Integer = 350
Dim resolutionY As Integer = 270
Call oCamera.SaveAsBitmap(ThisDoc.PathAndFileName(False) & ".bmp", resolutionX, resolutionY)
@ebaras wrote:
With this code, I currently have two issues.
- I cannot run this code in the assembly file. How can we adjust the code to work in assembly files as well?
- The quality of the images I'm getting as output is poor. It's important for the output images to have dimensions of 350x270 px, but they look bad at this size. Can we fix this?
Hi @ebaras,
I'm answering your question about first point ("code in the assembly"), I did a cleanup of your original code taking care about @WCrihfield suggestions (this doesn't change anything about what already said @WCrihfield on image resolution).
Dim oCamera As Camera = ThisApplication.ActiveView.Camera
oCamera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation
oCamera.ApplyWithoutTransition()
oCamera.Fit()
Dim resolutionX As Integer = 350
Dim resolutionY As Integer = 270
Call oCamera.SaveAsBitmap(ThisDoc.PathAndFileName(False) & ".bmp", resolutionX, resolutionY)
Yes, that would work pretty well, if the only need is to capture an image of the main assembly or of a part. But if images of all the assembly's referenced model documents are also needed, that would complicate things a lot more, because each of those referenced model documents would need to be 'visibly' opened as the active document on your screen before capturing the images.
Wesley Crihfield
(Not an Autodesk Employee)
Yes, that would work pretty well, if the only need is to capture an image of the main assembly or of a part. But if images of all the assembly's referenced model documents are also needed, that would complicate things a lot more, because each of those referenced model documents would need to be 'visibly' opened as the active document on your screen before capturing the images.
Wesley Crihfield
(Not an Autodesk Employee)
First of all, thank you both for your responses. :))
Size matters because I'll be uploading the outputs to another system. But as you said, you've given me some ideas about scaling. I've tried scaling a few times, but I got an 'unsupported' error in the outputs. The issue might not be related to scaling, I'm not sure.
Additionally, I found the attached code online. The code opens each product in the assembly file, extracts their profiles, and saves them in DXF format.
This is what I want. That is, to open the models in the assembly file, capture their images from specific -or home- angles, and save them in BMP format.
I'm trying some things but I'm curious if it'll work...
First of all, thank you both for your responses. :))
Size matters because I'll be uploading the outputs to another system. But as you said, you've given me some ideas about scaling. I've tried scaling a few times, but I got an 'unsupported' error in the outputs. The issue might not be related to scaling, I'm not sure.
Additionally, I found the attached code online. The code opens each product in the assembly file, extracts their profiles, and saves them in DXF format.
This is what I want. That is, to open the models in the assembly file, capture their images from specific -or home- angles, and save them in BMP format.
I'm trying some things but I'm curious if it'll work...
The code line seems a bit more understandable compared to yesterday. However, functionally, it's still the same. I'll try more today.
I tried scaling attempts, but kept getting errors each time.
Also, I still haven't figured out how to open and close the models in the tables within the assembly.
Here's the final version;
Sub Main() Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument ' If the active document is not an assembly file, display a warning and exit the subroutine If oDoc.DocumentType <> kAssemblyDocumentObject Then MsgBox("This rule can only be run from an assembly file.", vbExclamation, "Error") Exit Sub End If ' Get the name and path of the assembly file Dim oAsmName As String oAsmName = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName) Dim oPath As String oPath = System.IO.Path.GetDirectoryName(oDoc.FullFileName) ' Get the view of the assembly Dim oActiveView As View oActiveView = ThisApplication.ActiveView ' Configure camera settings Dim oCamera As Camera oCamera = oActiveView.Camera oCamera.ViewOrientationType = kIsoTopRightViewOrientation oCamera.ApplyWithoutTransition ThisApplication.ActiveView.Fit ' Save the view as a BMP image with specific resolution Dim resolutionX As Integer Dim resolutionY As Integer resolutionX = 350 resolutionY = 270 Dim saveName As String saveName = oPath & "\" & oAsmName & "_AssemblyImage.bmp" Call oActiveView.SaveAsBitmap(saveName, resolutionX, resolutionY) End Sub
The code line seems a bit more understandable compared to yesterday. However, functionally, it's still the same. I'll try more today.
I tried scaling attempts, but kept getting errors each time.
Also, I still haven't figured out how to open and close the models in the tables within the assembly.
Here's the final version;
Sub Main() Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument ' If the active document is not an assembly file, display a warning and exit the subroutine If oDoc.DocumentType <> kAssemblyDocumentObject Then MsgBox("This rule can only be run from an assembly file.", vbExclamation, "Error") Exit Sub End If ' Get the name and path of the assembly file Dim oAsmName As String oAsmName = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName) Dim oPath As String oPath = System.IO.Path.GetDirectoryName(oDoc.FullFileName) ' Get the view of the assembly Dim oActiveView As View oActiveView = ThisApplication.ActiveView ' Configure camera settings Dim oCamera As Camera oCamera = oActiveView.Camera oCamera.ViewOrientationType = kIsoTopRightViewOrientation oCamera.ApplyWithoutTransition ThisApplication.ActiveView.Fit ' Save the view as a BMP image with specific resolution Dim resolutionX As Integer Dim resolutionY As Integer resolutionX = 350 resolutionY = 270 Dim saveName As String saveName = oPath & "\" & oAsmName & "_AssemblyImage.bmp" Call oActiveView.SaveAsBitmap(saveName, resolutionX, resolutionY) End Sub
@ebaras you assigned "ActiveDocument" to "oDoc" before checking out "DocumentType" and this is not a good idea.
I tought to suggest you some adjustments to your code, but you didn't use anything about my last code tips.
@ebaras you assigned "ActiveDocument" to "oDoc" before checking out "DocumentType" and this is not a good idea.
I tought to suggest you some adjustments to your code, but you didn't use anything about my last code tips.
I actually tried it, but to be honest I do most of my coding with ChatGPT. It was deleted during the changes.
I get an error when I try to add the code. When I write it this way, I get this error.
"Error on line 42 in rule: Rule12, in document: Assembly1.iam
No public member 'PathAndFileName' of type 'AssemblyDocument' was found."
I think I'm doing something wrong somewhere.
Sub Main() Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument ' If the active document is not an assembly file, display a warning and exit the subroutine If oDoc.DocumentType <> kAssemblyDocumentObject Then MsgBox("This rule can only be run from an assembly file.", vbExclamation, "Error") Exit Sub End If ' Get the name and path of the assembly file Dim oAsmName As String oAsmName = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName) Dim oPath As String oPath = System.IO.Path.GetDirectoryName(oDoc.FullFileName) ' Get the view of the assembly Dim oActiveView As View oActiveView = ThisApplication.ActiveView ' Configure camera settings Dim oCamera As Camera oCamera = oActiveView.Camera oCamera.ViewOrientationType = kIsoTopRightViewOrientation oCamera.ApplyWithoutTransition ThisApplication.ActiveView.Fit ' Save the view as a BMP image with specific resolution Dim resolutionX As Integer Dim resolutionY As Integer resolutionX = 350 resolutionY = 270 Dim saveName As String saveName = oPath & "\" & oAsmName & "_AssemblyImage.bmp" Call oActiveView.SaveAsBitmap(saveName, resolutionX, resolutionY) ' Save the view using the camera settings oCamera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation oCamera.ApplyWithoutTransition() oCamera.Fit() Call oCamera.SaveAsBitmap(oDoc.PathAndFileName(False) & ".bmp", resolutionX, resolutionY) End Sub
I actually tried it, but to be honest I do most of my coding with ChatGPT. It was deleted during the changes.
I get an error when I try to add the code. When I write it this way, I get this error.
"Error on line 42 in rule: Rule12, in document: Assembly1.iam
No public member 'PathAndFileName' of type 'AssemblyDocument' was found."
I think I'm doing something wrong somewhere.
Sub Main() Dim oDoc As AssemblyDocument oDoc = ThisApplication.ActiveDocument ' If the active document is not an assembly file, display a warning and exit the subroutine If oDoc.DocumentType <> kAssemblyDocumentObject Then MsgBox("This rule can only be run from an assembly file.", vbExclamation, "Error") Exit Sub End If ' Get the name and path of the assembly file Dim oAsmName As String oAsmName = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName) Dim oPath As String oPath = System.IO.Path.GetDirectoryName(oDoc.FullFileName) ' Get the view of the assembly Dim oActiveView As View oActiveView = ThisApplication.ActiveView ' Configure camera settings Dim oCamera As Camera oCamera = oActiveView.Camera oCamera.ViewOrientationType = kIsoTopRightViewOrientation oCamera.ApplyWithoutTransition ThisApplication.ActiveView.Fit ' Save the view as a BMP image with specific resolution Dim resolutionX As Integer Dim resolutionY As Integer resolutionX = 350 resolutionY = 270 Dim saveName As String saveName = oPath & "\" & oAsmName & "_AssemblyImage.bmp" Call oActiveView.SaveAsBitmap(saveName, resolutionX, resolutionY) ' Save the view using the camera settings oCamera.ViewOrientationType = ViewOrientationTypeEnum.kIsoTopRightViewOrientation oCamera.ApplyWithoutTransition() oCamera.Fit() Call oCamera.SaveAsBitmap(oDoc.PathAndFileName(False) & ".bmp", resolutionX, resolutionY) End Sub
I did tests of my code before submission and work perfectly, but if chatGPT is the Master.... Ok, go with it and good luck 🙂
I did tests of my code before submission and work perfectly, but if chatGPT is the Master.... Ok, go with it and good luck 🙂
It sounds like I've been misunderstanding myself. I really don't understand the iLogic, and I'm trying to do something.
Yes, the code you provided helps me to take a pic, but it doesn't do the other things I want. As I try to add more things, the values change.
I saw your code and that's why I'm grateful. But I'm trying to add other things as well.
Thank you very much for your well wishes and contribution.
It sounds like I've been misunderstanding myself. I really don't understand the iLogic, and I'm trying to do something.
Yes, the code you provided helps me to take a pic, but it doesn't do the other things I want. As I try to add more things, the values change.
I saw your code and that's why I'm grateful. But I'm trying to add other things as well.
Thank you very much for your well wishes and contribution.
Ok, have a nice day.
Ok, have a nice day.
Can't find what you're looking for? Ask the community or share your knowledge.