Message 1 of 2
Changing color and view angle through VBA with a loop

Not applicable
02-05-2019
10:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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