Changing color and view angle through VBA with a loop

Changing color and view angle through VBA with a loop

Anonymous
Not applicable
415 Views
1 Reply
Message 1 of 2

Changing color and view angle through VBA with a loop

Anonymous
Not applicable

Hello everyone,

 

I have a little problem. I try to run an assembly and change the color of some parts and the camera angle and save the image as a png. Right now I managed to change the angle and save a png, but could not figure out on how to put some RGB colors in to the parts. The goal is to have multiple pictures from the same assembly, but with different colors and camera angles. How can I include some colors and add this to the whole part? 

For example the part "cubform1" is blue, but I want it to have the RGB colors of (200, 100, 200), is there a way?

 

For each camera view, change color of 2 parts and save it as png. Change view and 2 colors and save... etc.

 

This would really be a great help! This is my code so far:

 

Sub variation()
Dim oDoc As Document
Set oDoc = ThisApplication.ActiveDocument
Dim oView As View
Set oView = oDoc.Views(1)
Set oCamera = oView.Camera
oCamera.Apply
Dim oTO As TransientObjects
Set oTO = ThisApplication.TransientObjects
Dim oTop As Color
Set oTop = oTO.CreateColor(255, 255, 255)
Dim oBottom As Color
Set oBottom = oTO.CreateColor(255, 255, 255)
Dim dsplmode As String
Dim i As Integer
Dim i2 As String
Dim filename As String
Dim User As String
dsplmode = 0
Dim k As Integer
'Starten der Schleife
For k = 1 To 19
    If ThisApplication.ActiveView.DisplayMode = kShadedRendering Then
    dsplmode = 1
    ThisApplication.ActiveView.DisplayMode = kShadedWithEdgesRendering
    End If
    i = 0
    'For i = 1 To 99 Step 1
    For i = 1 To 17 Step 1
        If i < 10 Then
        i2 = "0" + CStr(i)
        End If
        If i > 9 Then
        i2 = "" + CStr(i)
        End If
        User = Environ(" USERNAME ")
        filename = "C:\Users\" + User + "\Desktop\Bild_" + i2 + ".png"
        If Dir(filename) = "" Then Exit For
    Next
    If k < 10 And k > 0 Then
    oCamera.SaveAsBitmap filename, 3840, 2160, oTop, oBottom
    ElseIf k > 10 And k < 20 Then
    oCamera.ViewOrientationType = kIsoBottomLeftViewOrientation
    oCamera.Apply
    oCamera.SaveAsBitmap filename, 3840, 2160, oTop, oBottom
    End If
    If dsplmode = 1 Then
    ThisApplication.ActiveView.DisplayMode = kShadedRendering
    End If
Next k

End Sub
0 Likes
416 Views
1 Reply
Reply (1)
Message 2 of 2

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous ,

 

Hoping that suggestions in the below blog like may be helpful.

 

https://adndevblog.typepad.com/manufacturing/2013/07/inventor-api-change-the-color-of-a-selected-face-in-an-assembly-document.html

 

Thanks and regards


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes