Inventor Customization

Inventor Customization

Reply
Valued Mentor
AlexF1980
Posts: 322
Registered: ‎07-05-2005
Message 1 of 12 (4,551 Views)

Inventor Screenshot Tool

4551 Views, 11 Replies
05-18-2010 04:11 AM
Hi folks,

For some time now I've been using a screenshot add-in (attached) similar to that posted by Kean Walmsley [here|http://bit.ly/cpiVmk] which was created by another Autodesk developer (Xiaodong Liang) and have been attempting to make it work in a 3D environment.

The output part of the tool works no problem, as it uses the Viewposition information provided by the OnMouseUp event. I have been trying to figure out the best method for getting the 3d points I need, which are perpendicular to the current view.

I had thought that this sample from the API Reference would help me but so far no luck.

{code}
Private Sub ProjectPoint(ByVal ModelPosition As Inventor.Point, ByVal WorkPointPosition As Inventor.Point, ProjectedPoint As Inventor.Point)

' Set a reference to the camera object
Dim oCamera As Inventor.Camera
Set oCamera = ThisApplication.ActiveView.Camera

Dim oVec As Vector
Set oVec = oCamera.Eye.VectorTo(oCamera.Target)

Dim oLine As Line
Set oLine = ThisApplication.TransientGeometry.CreateLine(ModelPosition, oVec)

' Create the z-axis vector
Dim oZAxis As Vector
Set oZAxis = ThisApplication.TransientGeometry.CreateVector(0, 0, 1)

' Create a plane parallel to the X-Y plane
Dim oWPPlane As Plane
Set oWPPlane = ThisApplication.TransientGeometry.CreatePlane(WorkPointPosition, oZAxis)

Set ProjectedPoint = oWPPlane.IntersectWithLine(oLine)
End Sub
{code}

Can anyone shed some light on what I'm doing wrong?

Thanks in advance,

Alex. Edited by: vegbruiser on May 18, 2010 12:11 PM
*Brian Ekins \(Autodesk\)
Message 2 of 12 (4,551 Views)

Re: Inventor Screenshot Tool

05-21-2010 03:42 PM in reply to: AlexF1980
Can you describe what it is you're trying to accomplish? I'm having trouble
understanding what you need to do.
--
Brian Ekins
Inventor API Product Designer
http://blogs.autodesk.com/modthemachine
Valued Mentor
AlexF1980
Posts: 322
Registered: ‎07-05-2005
Message 3 of 12 (4,551 Views)

Re: Inventor Screenshot Tool

05-24-2010 03:14 AM in reply to: AlexF1980
Hi Brian,

This started with the "Plug-in of the month" series of posts that Kean has been posting. I suggested to him that it would be handy to have the screen shot functionality in Inventor.

A couple of weeks later, a developer called Xiadong Liang contacted me with the code I attached to the OP.

We have been using the tool for some time, but wanted to have the option of easily outputting screen shots from parts/assemblies without having to use a third-party tool (such as Jing, or Screenpresso)

It's this functionality that I've been struggling with. The original code is designed to work in .idw files where the view is always looking at the XY plane.

The code I have cobbled together still provides the screen shot function, but the selection box doesn't display correctly.

I've created 2 videos showing the tool working and not working, but I'm having trouble uploading anything to YouTube etc. today.

Thanks,

Alex.
Distinguished Contributor
peter.townsend
Posts: 154
Registered: ‎03-12-2009
Message 4 of 12 (4,551 Views)

Re: Inventor Screenshot Tool

05-25-2010 04:38 PM in reply to: AlexF1980
If you're trying to take regular ol' screenshots, you can use the regular windows shortcuts, Print Screen for everything and ALT+Print Screen for the active window. And if you've got Office 2007 and OneNote, Windows Key + S will let you quickly save only a portion of the screen.

Inside of Inventor, if all you want to do is capture the model as on your screen, what's wrong with grabbing the Application.ActiveView and calling SaveAsBitmap?

This quick and dirty VBA script'll do it:
{code}
Sub x()
Dim a As Application
Set a = ThisApplication
Dim v As View
Set v = a.ActiveView
Call v.SaveAsBitmap("c:\temp\shot.bmp", 1024, 768)
End Sub
{code}

If you got a custom background, it'll even snag that. And if you want to save it in another format, you can open that image file and resave it as another format. In .NET you can call System.Drawing.Image methods to do that.

Judging from your post though, are you trying to write something that draws a selection box based on where the user clicks? If you want to cheat, you might be able to do something tricky with Windows Forms that graphically overlays a box over Inventor that follows your mouse. Then you can take those coordinates, relate them to the screenshot you can take from that SaveAsBitmap result (or WinAPI to take the screenshot into memory) and cut the image down using the mouse click coordinates.

I'll admit though that I'm not sure if it'd be more practical than trying to make Inventor API code work with both model space and drawing space. Just a thought though. Edited by: peter.townsend on May 25, 2010 6:42 PM

I just noticed the GetWindowExtents method on the View object. That'd make chopping the image via an overlay much easier.
Valued Mentor
AlexF1980
Posts: 322
Registered: ‎07-05-2005
Message 5 of 12 (4,551 Views)

Re: Inventor Screenshot Tool

05-26-2010 02:08 AM in reply to: AlexF1980
Thanks for your input Peter; I have this morning been sent the attached .vb file from my contact at Autodesk.

I've yet to figure out how to integrate this code into my solution, but it looks to be quite useful.

Here's the code for those of you too lazy to download the file:

{code}
Imports Inventor
Imports System.Drawing

Public Class InteractionEventsManager

Dim m_inventorApplication As Inventor.Application

Dim oCornerPt As Point2d
Dim oSize As Size

'Interaction Events
Private WithEvents m_InteractionEvents As InteractionEvents

'Mouse event
Private WithEvents m_MouseEvents As MouseEvents

'Pick event for selecting object
Dim WithEvents m_SelectEvents As SelectEvents

'flag to indicate the mouse is down
Private m_flagMouseDown As Boolean

' start point, for screenshot
Private m_MouseStartViewPt As Inventor.Point2d

'start point, for temporary selecting rectangle
Private m_StartModelPt As Inventor.Point

'flag to indicate screenshot is running
Dim isRunningScreenshot As Boolean

'graphics node
Dim oGiNode As GraphicsNode
'coordinate set for graphics node
Dim oCoordSet As GraphicsCoordinateSet
'color set for graphics node
Dim oColorSet As GraphicsColorSet
'Line strip Graphics
Dim oGiLineStripG As LineStripGraphics
'Line Graphics (for Inventor 2009 only)
Dim oGiLineG As LineGraphics



Public Sub New(ByVal oApp As Inventor.Application)
m_inventorApplication = oApp
oCornerPt = _
m_inventorApplication.TransientGeometry.CreatePoint2d(0, 0)
oSize = New Size()
End Sub

Public Sub DoSelectRegion( _
ByRef bmSize As Size, _
ByRef bmCornetPt As Inventor.Point2d)

StartEvent(True)
bmSize = oSize
bmCornetPt = oCornerPt
End Sub

Public Sub DoSelectObject( _
ByRef bmSize As Size, _
ByRef bmCornetPt As Inventor.Point2d)

StartEvent(False)
bmSize = oSize
bmCornetPt = oCornerPt
End Sub

Private Sub StartEvent(ByVal region_or_object As Boolean)

'start interaction event
If m_InteractionEvents Is Nothing Then
m_InteractionEvents = _
m_inventorApplication.CommandManager.CreateInteractionEvents()
Else
m_InteractionEvents.Stop()
End If

m_InteractionEvents.InteractionDisabled = False

If region_or_object Then
'get mouse event
If m_MouseEvents Is Nothing Then
m_MouseEvents = m_InteractionEvents.MouseEvents
m_MouseEvents.MouseMoveEnabled = True
m_MouseStartViewPt = _
m_inventorApplication.TransientGeometry.CreatePoint2d(0, 0)
m_flagMouseDown = False
End If
Else
'get select event
If m_SelectEvents Is Nothing Then
m_SelectEvents = m_InteractionEvents.SelectEvents
m_SelectEvents.SingleSelectEnabled = False
m_SelectEvents.WindowSelectEnabled = True
End If
End If

m_InteractionEvents.Name = "MyScreenshot"

'start
m_InteractionEvents.Start()

Do While Not m_InteractionEvents Is Nothing
If m_inventorApplication.SoftwareVersion.Major > 13 Then
m_inventorApplication.UserInterfaceManager.DoEvents()
Else
System.Windows.Forms.Application.DoEvents()
End If
Loop
End Sub

Private Sub m_InteractionEvents_OnTerminate() _
Handles m_InteractionEvents.OnTerminate

m_InteractionEvents.InteractionGraphics.PreviewClientGraphics.Delete()
m_inventorApplication.ActiveView.Update()
m_flagMouseDown = False
m_InteractionEvents.Stop()
m_MouseEvents = Nothing
m_SelectEvents = Nothing
m_InteractionEvents = Nothing
End Sub

Private Sub m_MouseEvents_OnMouseDown( _
ByVal Button As Inventor.MouseButtonEnum, _
ByVal ShiftKeys As Inventor.ShiftStateEnum, _
ByVal ModelPosition As Inventor.Point, _
ByVal ViewPosition As Inventor.Point2d, _
ByVal View As Inventor.View) Handles m_MouseEvents.OnMouseDown

'if the interaction event is MyScreenshot,
'then get the view position and model position

If m_InteractionEvents.Name = "MyScreenshot" Then
m_MouseStartViewPt = ViewPosition
m_StartModelPt = ModelPosition
m_flagMouseDown = True

'clean the last graphics
m_InteractionEvents.InteractionGraphics.PreviewClientGraphics.Delete()
m_inventorApplication.ActiveView.Update()

'gi node
oGiNode = m_InteractionEvents.InteractionGraphics.PreviewClientGraphics.AddNode(1)
oCoordSet = m_InteractionEvents.InteractionGraphics.GraphicsDataSets.CreateCoordinateSet(1)

'color set
oColorSet = m_InteractionEvents.InteractionGraphics.GraphicsDataSets.CreateColorSet(1)
Call oColorSet.Add(1, 255, 0, 0)

Dim tg As TransientGeometry = m_inventorApplication.TransientGeometry
Dim tempP As Inventor.Point = tg.CreatePoint(ViewPosition.X, ViewPosition.Y, 0)

oCoordSet.Add(1, tempP)
oCoordSet.Add(2, tempP)
oCoordSet.Add(3, tempP)
oCoordSet.Add(4, tempP)
oCoordSet.Add(5, tempP)

Try
If Not oGiLineStripG Is Nothing Then
oGiLineStripG.Delete()
oGiLineStripG = Nothing
End If
oGiLineStripG = oGiNode.AddLineStripGraphics()
oGiLineStripG.CoordinateSet = oCoordSet
oGiLineStripG.ColorSet = oColorSet
oGiLineStripG.BurnThrough = True
Catch ex As Exception
'a problem in Inventor 2009( R13 ) with
'LineStripGraphics.BurnThrough. Use LineGraphics as workaround

If Not oGiLineG Is Nothing Then
oGiLineG.Delete()
oGiLineG = Nothing
End If

oGiLineG = oGiNode.AddLineGraphics()
oGiLineG.CoordinateSet = oCoordSet
oGiLineG.ColorSet = oColorSet
oGiLineG.BurnThrough = True
End Try


End If
End Sub

' version 2010-05-23: to solve the issue in Perspective View
Private Sub m_MouseEvents_OnMouseMove( _
ByVal Button As Inventor.MouseButtonEnum, _
ByVal ShiftKeys As Inventor.ShiftStateEnum, _
ByVal ModelPosition As Inventor.Point, _
ByVal ViewPosition As Inventor.Point2d, _
ByVal View As Inventor.View) Handles m_MouseEvents.OnMouseMove

'if the interaction event is MyScreenshot, draw selecting rectangle.
If m_InteractionEvents.Name = "MyScreenshot" And m_flagMouseDown Then

Dim tg As TransientGeometry = m_inventorApplication.TransientGeometry

Dim P1 As Inventor.Point = tg.CreatePoint(m_MouseStartViewPt.X, -m_MouseStartViewPt.Y, 0)
Dim P3 As Inventor.Point = tg.CreatePoint(ViewPosition.X, -ViewPosition.Y, 0)
Dim P4 As Inventor.Point = tg.CreatePoint(P1.X, P3.Y, 0)
Dim P2 As Inventor.Point = tg.CreatePoint(P3.X, P1.Y, 0)

'update coordinates

oCoordSet(1) = P1
oCoordSet(2) = P2
oCoordSet(3) = P3
oCoordSet(4) = P4
oCoordSet(5) = P1

'add line strip
If Not oGiLineStripG Is Nothing Then
oGiLineStripG.SetTransformBehavior(P1, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling, 1)
oGiLineStripG.SetViewSpaceAnchor(P1, m_MouseStartViewPt, ViewLayoutEnum.kTopLeftViewCorner)
ElseIf Not oGiLineG Is Nothing Then
oGiLineG.SetTransformBehavior(P1, DisplayTransformBehaviorEnum.kFrontFacingAndPixelScaling)
oGiLineG.SetViewSpaceAnchor(P1, m_MouseStartViewPt, ViewLayoutEnum.kTopLeftViewCorner)
End If


m_inventorApplication.ActiveView.Update()

End If
End Sub


Private Sub m_MouseEvents_OnMouseUp( _
ByVal Button As Inventor.MouseButtonEnum, _
ByVal ShiftKeys As Inventor.ShiftStateEnum, _
ByVal ModelPosition As Inventor.Point, _
ByVal ViewPosition As Inventor.Point2d, _
ByVal View As Inventor.View) Handles m_MouseEvents.OnMouseUp

'if the interaction event is MyScreenshot, create the image
If m_InteractionEvents.Name = "MyScreenshot" Then

m_InteractionEvents.InteractionGraphics.PreviewClientGraphics.Delete()
m_inventorApplication.ActiveView.Update()

If Not oGiLineStripG Is Nothing Then
oGiLineStripG.Delete()
oGiLineStripG = Nothing
End If

If Not oGiLineG Is Nothing Then
oGiLineG.Delete()
oGiLineG = Nothing
End If

'stop interaction event
m_InteractionEvents.SetCursor(CursorTypeEnum.kCursorBuiltInArrow)
m_flagMouseDown = False
m_InteractionEvents.Stop()
m_MouseEvents = Nothing
m_InteractionEvents = Nothing

'prepare size of the image region, in pixel

oSize = _
New Size( _
Math.Abs( _
ViewPosition.X - m_MouseStartViewPt.X), _
Math.Abs(ViewPosition.Y - m_MouseStartViewPt.Y))

If ViewPosition.X > m_MouseStartViewPt.X And _
ViewPosition.Y > m_MouseStartViewPt.Y Then

oCornerPt = m_MouseStartViewPt
ElseIf ViewPosition.X > m_MouseStartViewPt.X And _
ViewPosition.Y < m_MouseStartViewPt.Y Then

oCornerPt.X = m_MouseStartViewPt.X
oCornerPt.Y = ViewPosition.Y
ElseIf ViewPosition.X < m_MouseStartViewPt.X And _
ViewPosition.Y > m_MouseStartViewPt.Y Then

oCornerPt.X = ViewPosition.X
oCornerPt.Y = m_MouseStartViewPt.Y
Else
oCornerPt = ViewPosition
End If

'take the view position in screen, calculate
'the real pixel data of the corners

oCornerPt.X = View.Left + oCornerPt.X
oCornerPt.Y = View.Top + oCornerPt.Y
End If

End Sub

Private Sub m_SelectEvents_OnSelect( _
ByVal JustSelectedEntities As Inventor.ObjectsEnumerator, _
ByVal SelectionDevice As Inventor.SelectionDeviceEnum, _
ByVal ModelPosition As Inventor.Point, _
ByVal ViewPosition As Inventor.Point2d, _
ByVal View As Inventor.View) Handles m_SelectEvents.OnSelect

'reserved for future
End Sub

End Class
{code}

I understand that the above code will form part of a plug-in on the Autodesk labs website shortly.
Distinguished Contributor
cadfish1
Posts: 565
Registered: ‎02-12-2009
Message 6 of 12 (4,551 Views)

Re: Inventor Screenshot Tool

05-26-2010 10:00 AM in reply to: AlexF1980
I've figured out how to implement it. Before I discuss how to implement it, you need a little background information first. This programming is currently only capable of drawing the region rectangle as you drag & drop but it does NOT contain the code to make the capture so I added it to InteractionEventsManager.vb (see comments and code below). They've put in some intrastructure for object preselection but no guts (yet) for capturing. They have two Public Subs you can to execute: DoSelectRegion and DoSelectObject. However, I can't figure out why they have arguments (Size and Inventor.Point2d). From what I can tell, these 2 parameters are calculated as you select the corners of the region. I was able to supply arguments and it worked (commented out code below). I noticed DoSelectRegion and DoSelectObject both use the Private Sub StartEvent which as an Boolean argument that determines if the code is to process a region (True) or selected objects (False). So I changed StartEvent from Private to Public so I could execute it from the button's code (below) in StandardAddInServer.vb (main addin file)

Implementation:

InteractionEventsManager.vb is a Class module. You add InteractionEventsManager.vb to your addin then create a button with the code below which starts the screen shot programming (which waits for you to drag & drop oppsing corners of the region). If you want to execute StartEvent, you must make it Public first otherwise use the code below for DoSelectRegion.

{code}
Private Sub moBtnDef_ScreenShot_OnExecute(ByVal Context As Inventor.NameValueMap) Handles moBtnDef_ScreenShot.OnExecute
Dim oScreenShot As New InteractionEventsManager(goInvApp)
'oScreenShot.DoSelectRegion(New System.Drawing.Size, goInvApp.TransientGeometry.CreatePoint2d(0, 0))
oScreenShot.StartEvent(True)
End Sub


'Add this to the top of InteractionEventsManager.vb
Imports System.Drawing.Imaging

'Add the follow to m_MouseEvents_OnMouseUp right after the line: oCornerPt.Y = View.Top + oCornerPt.Y

Dim bmp As Bitmap = New Bitmap(oSize.Width, oSize.Height, PixelFormat.Format32bppArgb)
Dim gfx As Graphics = Graphics.FromImage(bmp)
gfx.CopyFromScreen(oCornerPt.X, oCornerPt.Y, 0, 0, oSize, CopyPixelOperation.SourceCopy)
System.Windows.Forms.Clipboard.SetImage(bmp)

Dim ofileDlg As System.Windows.Forms.SaveFileDialog = _
New System.Windows.Forms.SaveFileDialog
ofileDlg.Filter = " files" + "(*." + "jpg" + ")|*." + "jpg" + "|All files (*.*)|*.*"

If ofileDlg.ShowDialog() = DialogResult.OK Then
bmp.Save(ofileDlg.FileName)
End If

{code}

When Autodesk finishes the code for the object selection, I hope they post it (or a link to it) in this discussion group. Edited by: cadfish1 on May 26, 2010 5:00 PM
Distinguished Contributor
cadfish1
Posts: 565
Registered: ‎02-12-2009
Message 7 of 12 (4,551 Views)

Re: Inventor Screenshot Tool

05-26-2010 12:57 PM in reply to: AlexF1980
I've also figured out (with help from other threads) how to make the background white for the capture then set it back when done. The code below goes in m_MouseEvents_OnMouseUp. The first line of code below shows you the placement. Replace everything below this line in the code I supplied before with the code after this line below. Works great, I love it. Thanks guys. I can't wait until Autodesk finishes the preseleted object captures.
{code}
oCornerPt.Y = View.Top + oCornerPt.Y

Dim oSheetSettings As SheetSettings = Nothing
Dim oColor As Inventor.Color = Nothing
Dim oColorSchemes As ColorSchemes = Nothing
Dim oColorScheme As ColorScheme = Nothing
Dim lBackgroundType As BackgroundTypeEnum
If m_inventorApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
oSheetSettings = m_inventorApplication.ActiveDocument.SheetSettings
oColor = oSheetSettings.SheetColor
oSheetSettings.SheetColor = m_inventorApplication.TransientObjects.CreateColor(255, 255, 255) 'White
Else
oColorSchemes = m_inventorApplication.ColorSchemes
oColorScheme = m_inventorApplication.ActiveColorScheme
lBackgroundType = oColorSchemes.BackgroundType
oColorSchemes.Item("Presentation").Activate()
oColorSchemes.BackgroundType = BackgroundTypeEnum.kOneColorBackgroundType
End If
m_inventorApplication.ActiveView.Update()

Dim bmp As Bitmap = New Bitmap(oSize.Width, oSize.Height, PixelFormat.Format32bppArgb)
Dim gfx As Graphics = Graphics.FromImage(bmp)
gfx.CopyFromScreen(oCornerPt.X, oCornerPt.Y, 0, 0, oSize, CopyPixelOperation.SourceCopy)

System.Windows.Forms.Clipboard.SetImage(bmp)

Dim ofileDlg As System.Windows.Forms.SaveFileDialog = _
New System.Windows.Forms.SaveFileDialog
ofileDlg.Title = "On the Clipboard too"
ofileDlg.Filter = "JPEG files" + "(*." + "jpg" + ")|*." + "jpg" + "|All files (*.*)|*.*"
If ofileDlg.ShowDialog() = DialogResult.OK Then
bmp.Save(ofileDlg.FileName)
End If

If m_inventorApplication.ActiveDocument.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
oSheetSettings.SheetColor = oColor
Else
m_inventorApplication.ColorSchemes.Item(oColorScheme.Name).Activate()
oColorSchemes.BackgroundType = lBackgroundType
End If
{code}
Valued Mentor
AlexF1980
Posts: 322
Registered: ‎07-05-2005
Message 8 of 12 (4,551 Views)

Re: Inventor Screenshot Tool

05-27-2010 03:01 AM in reply to: AlexF1980
Thanks for your efforts Cadfish, I figured it was something simple I was missing. (Implementing the class I posted)

I also like the "Set background to white" functionality too. Good work. :-)

I'm not using it yet, but I believe Inventor 2011 allows you more customisation of view styles, so I guess it would be possible to standardize the output style from within this tool?

I hope to install IV2011 in the next few days so will have the opportunity to test the above statement.
Distinguished Contributor
cadfish1
Posts: 565
Registered: ‎02-12-2009
Message 9 of 12 (4,551 Views)

Re: Inventor Screenshot Tool

05-27-2010 05:20 AM in reply to: AlexF1980
You're welcome but I did it for selfish reasons. We create a lot of PowerPoint presenations which uses screen captures from Inventor (sometimes 100+ per presentation) so this will save us a few clicks per capture. Thank you for sharing.

What do you mean by "customization of view styles"? If you mean background color and style (gradient, 1 color, etc) then yes you can set it how you like. I would think you'd offer another command (button - form) for the user to select the color and style and save that somewhere (SaveSetting) for the screen capture code to utilize (GetSetting).

If you need help getting it going, let me know (beebema@westinghouse.com).
Valued Mentor
AlexF1980
Posts: 322
Registered: ‎07-05-2005
Message 10 of 12 (4,551 Views)

Re: Inventor Screenshot Tool

05-27-2010 06:11 AM in reply to: AlexF1980
It sounds like you would really benefit from using Autodesk Inventor Publisher - especially as PowerPoint is one of the formats it's capable of outputting to.

We had access to the Technology Preview and found it lacking in a number of areas, and having seen the trial version, I'm happy to say it's been improved somewhat since the TP. We don't yet have enough future work to make purchasing a copy viable, but what we have shown our client so far has been very well received.

Getting back on topic; I've seen a few videos posted by Rob Cohee that show AutoCAD-style shading & (I think) rendering within the Inventor window.

In fact, here's a link to one of them: http://bit.ly/aA3RFn (There are a few more available if you click through to YouTube)

I hadn't considered adding a button to set the screenshot "style" - If I did do that I'd maybe try and make it function the same as the other tool I've been working on which allows you to create two Inventor drawings using the same drawing block; I did this because our client requires us to send them specific drawing borders (which are IMHO pretty crappy), whereas ours are a lot simpler/cleaner/use nicer fonts and we can send them to potential suppliers without giving away who our client is.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.