Raytracing with iLogic

Raytracing with iLogic

Anonymous
Not applicable
2,002 Views
13 Replies
Message 1 of 14

Raytracing with iLogic

Anonymous
Not applicable

I am trying to automate a series of images from an Inventor Model with iLogic.

 

So far I can export everything I want by changing Shading Styles and Lighting, but I am unable to get a Ray Traced image.

 

Have found some code to set the Display Mode to Realistic...

oView.DisplayMode = Inventor.DisplayModeEnum.kRealisticRendering

...and some more code to set Quality...

oView.RayTracingQuality = Inventor.RayTracingQualityEnum.kHighRayTracingQuality

...but I can't get it to start Ray Tracing, or set a time for it to save after.

 

I may very well be barking up the wrong tree here, but is this do-able?

 

I just want to automate the following;

1. Turn on Ray Tracing

2. Wait 90 seconds

3. Save the resulting image

 

0 Likes
Accepted solutions (1)
2,003 Views
13 Replies
Replies (13)
Message 2 of 14

chandra.shekar.g
Autodesk Support
Autodesk Support

@Anonymous,

 

Hoping that View.SaveAsBitmapWithRayTracing Method would be useful to save ray traced image. For more details, please refer below API documentation link.

http://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-5870AECC-3A31-47E3-992A-AB3D3301C364

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 14

Anonymous
Not applicable

Hello Chandra, thank you for the reply.

 

I am trying the method you have suggested, but am now getting an error.

I do not know what this error is telling me...

 

"Number of parameters specified does not match the expected number."

Below is a sample of my code:

 

oView = ThisApplication.ActiveView

Dim originalSchema As String
originalSchema = ThisApplication.ActiveColorScheme.Name
Dim originalBkg As BackgroundTypeEnum
originalBkg = ThisApplication.ColorSchemes.BackgroundType
ThisApplication.ColorSchemes.Item("Presentation").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.SaveAsBitmapWithRayTracing(picName & ".png", oView.Width, oView.Height)

If originSetOff Then
 ThisApplication.DisplayOptions.Show3DIndicator = True
End If
ThisApplication.ColorSchemes.Item(originalSchema).Activate
ThisApplication.ColorSchemes.BackgroundType = originalBkg

This works fine if I use SaveAsBitmap but throws the above error when using SaveAsBitmapWithRayTracing

 

0 Likes
Message 4 of 14

YuhanZhang
Autodesk
Autodesk

Here is the iLogic code to use Ray Tracing and save picture for it:

 

Sub Main()
	Dim oView As Inventor.View
	oView = ThisApplication.ActiveView
	
	oView.DisplayMode = DisplayModeEnum.kRealisticRendering
	
	' start ray tracing
	oView.RayTracing=  True 
	oView.RayTracingQuality = RayTracingQualityEnum.kHighRayTracingQuality
	
	Dim bStop As Boolean 
	
	Do 
		If (oView.RayTracingProgress = 1) Then
			bStop = True
			oView.SaveAsBitmapWithRayTracing ("C:\temp\mypic.png")
		End If
		
		If (oView.RayTracing = False) Then
				bStop = True 
		End If
	Loop Until (bStop)
	
	' turn off ray tracing
	oView.RayTracing=False 
End Sub

Hope it helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 5 of 14

Anonymous
Not applicable

Hello Rocky,

Thank you very much for your reply.

The code you have provided seems to work for me, but does not allow for raytracing to run for any period of time.

The image I get is in the 'realistic' visual style, but has not actually been raytraced (see below)

from iLogic Codefrom iLogic Code

Below is an example of the same image, but raytraced for approx 60 seconds...

 

manually raytracedmanually raytraced

 

When I run your code I see Inventor turn on raytracing and then instantly disable it.

I assumed the line...

If (oView.RayTracingProgress = 1) Then

...would control the percentage amount  to complete raytracing, but if I change this figure to anything other than 1 the program just hangs until I force close.

I also find that if I run your code a second time I end up in the same situation with the program hanging.

 

0 Likes
Message 6 of 14

YuhanZhang
Autodesk
Autodesk

Updated the code, please try it and let me if it works better:

 

Sub Main()
	Dim oView As Inventor.View
	oView = ThisApplication.ActiveView
	
	oView.DisplayMode = DisplayModeEnum.kRealisticRendering
	
	' start ray tracing
	oView.RayTracing=  True 
	oView.RayTracingQuality = RayTracingQualityEnum.kHighRayTracingQuality
	
	Dim bStop As Boolean 
	
	Do 
		ThisApplication.UserInterfaceManager.DoEvents
		
		If (oView.RayTracingProgress = 1) Then
			bStop = True
			oView.SaveAsBitmapWithRayTracing ("C:\temp\mypic.png")
		End If
		
		If (oView.RayTracing = False) Then
				bStop = True 
		End If
	Loop Until (bStop)
	
	' turn off ray tracing
	oView.RayTracing=False 
End Sub

The code will allow Inventor to draw the ray tracing. Current Inventor behavior is if you draw the ray tracing once and then if you try to redraw it but no change to the graphic view(zoom/pan/rotate or model change) then it won't redraw it because it will use the last time cached  result.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 7 of 14

Anonymous
Not applicable

Hi Rocky,

 

This is working much better now. I am getting a raytraced image output as required.

 

It seems to run until 100% which gives a nice image, but I would like to stop it earlier.

 

Is it possible to set a finish percentage, or perhaps set a time for the raytracing process?

 

I really only need 60 - 90 seconds worth of raytracing to get a suitable image...

 

 

P.S Thank you very much for your help so far. I don't know how I would have got here without your assistance : )

 

0 Likes
Message 8 of 14

YuhanZhang
Autodesk
Autodesk

You can change the value for the RayTracingProgress to decide when you want to pause it(the value indicate the percentage of the full progress), below updated code just sets it to 0.5 means it will pause at the 50% of full progress:

Sub Main()
Dim oView As Inventor.View
oView = ThisApplication.ActiveView

oView.DisplayMode = DisplayModeEnum.kRealisticRendering

' start ray tracing
oView.RayTracing = True
oView.RayTracingQuality = RayTracingQualityEnum.kHighRayTracingQuality

Dim bStop As Boolean

Do
ThisApplication.UserInterfaceManager.DoEvents

If (oView.RayTracingProgress = 0.5) Then
oView.IsRayTracingPaused = True
bStop = True
oView.SaveAsBitmapWithRayTracing ("C:\temp\mypic.png")
End If

If (oView.RayTracing = False) Then
bStop = True
End If
Loop Until (bStop)

' turn off ray tracing
oView.RayTracing = False
End Sub

 

Also if you want to hard-code the time(e.g. 50 second), you can also add a timer(calculate the elapsed time) to decide when to pause the progress and then terminate the ray tracing.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 9 of 14

Anonymous
Not applicable

Hi again Rocky,

 

Thank you for your help and patience : )

I am getting a nice image from your code now, but still can't seem to get the process to stop correctly at less than 100%.

If I change your code to 0.5 as suggested the raytracing still runs all the way to the end.

Funny thing is, it will not put out an image, just sits there waiting for me to do something...

Even if I do hit 'save' raytracing is still turned on.

When I hit 'disable' I get the following error...

 

Error in rule: Rule2, in document: GW357.iam

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))

 

Seems like the only way for it to save an image is if I leave that variable on '1'

 

How do I go about doing this as a time based process?

I think this would work better for me anyway.

I usually raytrace for 60 - 90 seconds and get a good enough image for my purposes.

 

Thank you again for all of your help, I owe you a beer if I ever meet you : )

0 Likes
Message 10 of 14

YuhanZhang
Autodesk
Autodesk
Accepted solution

I double checked this, and seems we can't set timer or detect the ray tracing progress in iLogic(or VBA), because if we use the DoEvents then we will give control to Inventor to call the ray tracing until it is completed(progress is 100%), if we don't call the DoEvents then Inventor can't do ray tracing. So currently we can only use DoEvents to allow Inventor to complete the ray tracing rendering and then save image for it. 

 

To accomplish your purpose we need to add a new event to monitor ray tracing then you can decide to save an image at e.g. 50% of the rendering progress. If you really need this event please log a wish to Idea.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 11 of 14

sverduyn
Contributor
Contributor

Hi,

 

I have a standalone vb.net app and would like to use raytracing but the above code does not work. You mentioned adding a new event to monitor ray tracing, do you know if this will be added or if is going to be added to the api. If not could you please tell me where to add it to the ideas or where else I could ask for this feature.

 

Thanks 

 

Shaun

0 Likes
Message 12 of 14

YuhanZhang
Autodesk
Autodesk

You can log Idea from below link:

 

https://forums.autodesk.com/t5/inventor-ideas/idb-p/v1232/label-name/api-ilogic

 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 13 of 14

jzarczynski
Advocate
Advocate

Hi guys,

 

I am bothering with this problem since 2 years.

 

I posted an idea:

https://forums.autodesk.com/t5/inventor-ideas/event-handler-detecting-raytracing-progress/idi-p/9525...

 

Please upvote, hopefully some day we will able to get the lacking functionality from autodesk.

@YuhanZhang I think it isn't very hard to implement.

0 Likes
Message 14 of 14

YuhanZhang
Autodesk
Autodesk

I created a story for this in our backlog, you can provide INVGEN-41200 to query its status later. 



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes