How to use Msflexgrid in Add-in?

How to use Msflexgrid in Add-in?

Anonymous
Not applicable
549 Views
7 Replies
Message 1 of 8

How to use Msflexgrid in Add-in?

Anonymous
Not applicable
Hi,everyone.

How can i use MsFlexgrids in add-in forms, is this possible?
I have created a test add-in with a Msflexgrid control in a form and when the form loads a error is diplayed, why?

Thanks for everyone replys.
0 Likes
550 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
Are you creating your Addin using the sample VB addin?

Are you using VB6?

What Error are you getting?

~Tom
0 Likes
Message 3 of 8

Anonymous
Not applicable
Hi, Tom.

I'm really needing help on this because i don´t know how to make the MSflexgrid work.

Yes, i´m using VB6.

the error displayed by inventor is:
Run-time error '5':
Invalid Procedure call or argument


The code is the following:

**********************Class module**************
Option Explicit

Implements ApplicationAddInServer
Private WithEvents MyAppEv As ApplicationEvents
Dim oApp As Inventor.Application

Private Sub ApplicationAddInServer_Activate(ByVal AddInSiteObject As Inventor.ApplicationAddInSite, ByVal FirstTime As Boolean)

' Save a reference to the Application object.
Set oApp = AddInSiteObject.Application
Set MyAppEv = oApp.ApplicationEvents


End Sub

Private Property Get ApplicationAddInServer_Automation() As Object
Set ApplicationAddInServer_Automation = Nothing
End Property

Private Sub ApplicationAddInServer_Deactivate()
Set oApp = Nothing
End Sub

Private Sub ApplicationAddInServer_ExecuteCommand(ByVal CommandID As Long)

End Sub


Private Sub MyAppEv_OnDocumentChange(ByVal DocumentObject As Document, _
ByVal BeforeOrAfter As EventTimingEnum, _
ByVal ReasonsForChange As CommandTypesEnum, _
ByVal Context As NameValueMap, _
HandlingCode As HandlingCodeEnum)


If BeforeOrAfter = kBefore Then

If DocumentObject.DocumentType = kPartDocumentObject Then

With Form1
Set .objPartDocument = DocumentObject
.Show vbModeless
End With

End If
End If
End Sub

****************************Form load**************
Option Explicit
'Private oApp As Inventor.Application
Private selrow As Long
Private selcol As Long
Public objPartDocument As Inventor.PartDocument

Public Sub form_load()


Dim MaxFldValLen As Long 'Stores the Maximum Field Value Length, Used for Automatic Resizing

Dim i As Integer
Dim nome_f, nome As String
Dim oPropSet As PropertySet
Dim oprop As Property
Dim func_ex As Integer

Set oPropSet = objPartDocument.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")

For i = 0 To oPropSet.Count
MsgBox "Form load"
MSFlexGrid1.FocusRect = flexFocusHeavy
MSFlexGrid1.SelectionMode = flexSelectionFree
MSFlexGrid1.Clear
MSFlexGrid1.FormatString = "Propriedade |valor |Função "
MSFlexGrid1.Rows = i + 1
MSFlexGrid1.Col = 1
MSFlexGrid1.TextStyle = flexTextInsetLight
MSFlexGrid1.TextMatrix(i, 1) = oPropSet.Item(i).Name
MSFlexGrid1.TextMatrix(i, 2) = oPropSet.Item(i).Value



MSFlexGrid1.AllowUserResizing = flexResizeBoth

Next i
end sub
0 Likes
Message 4 of 8

Anonymous
Not applicable
Can someone really help me on this issue?
Thanks.
0 Likes
Message 5 of 8

Anonymous
Not applicable
The problem in your program is a bit of confusion with index values. The
first item in a collection is always 1. The first row and column in a grid
are 0. You were trying to access item 0 from the properties collection
which is what was causing the problem. Here's a cleaned up version of your
Form_Load that works for me. You should also change where you're loading
the form. The OnDocumentChange is not a good place because this event fires
a lot.

Public Sub form_load()
Dim MaxFldValLen As Long 'Stores the Maximum Field Value Length, Used
for Automatic Resizing

Dim i As Integer
Dim nome_f As String, nome As String
Dim oPropSet As PropertySet
Dim oprop As Property
Dim func_ex As Integer

Set oPropSet =
AsmDoc.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")

MSFlexGrid1.Clear
MSFlexGrid1.FormatString = "Propriedade |valor |Função "
MSFlexGrid1.AllowUserResizing = flexResizeBoth
For i = 1 To oPropSet.Count
MSFlexGrid1.FocusRect = flexFocusHeavy
MSFlexGrid1.SelectionMode = flexSelectionFree
MSFlexGrid1.Rows = i + 1
MSFlexGrid1.TextStyle = flexTextInsetLight
MSFlexGrid1.TextMatrix(i, 1) = oPropSet.Item(i).Name
MSFlexGrid1.TextMatrix(i, 2) = oPropSet.Item(i).Value
Next i
End Sub
--
Brian Ekins
Autodesk Inventor API


wrote in message news:5138114@discussion.autodesk.com...
Can someone really help me on this issue?
Thanks.
0 Likes
Message 6 of 8

Anonymous
Not applicable
Thanks a lot Brian for your help.
0 Likes
Message 7 of 8

Anonymous
Not applicable
Hi, again Brian!

In your last reply you mention "You should also change where you're loading the form. The OnDocumentChange is not a good place because this event fires a lot".

Can you give a sample code, where i can see how to make the event to fire only one time, by document changing?

I´ve been trying to see this in the add-in samples of Inventor, but for a beginner the code makes me some confusion.

Thanks again for your reply and help.
0 Likes
Message 8 of 8

Anonymous
Not applicable
If you just want to know the first time a document is changed you should be
listening to the OnFileDirty event. This event is sent when a document
becomes "dirty". This means the document has changed somehow since the last
time it was saved and requires a save if you want to save those changes.

With events, you don't control when they're fired, but you can control if
you listen to them at all and what you do when the event if fired. In your
code you set a reference to the object that supports the event you want to
listen to. For example:

Set oAppEvents = oApp.ApplicationEvents

You have a sub in your program that Inventor calls for a specific event on
that object. In your case for OnDocumentChange. If you release the
reference to the object providing the event you'll quit getting that event.
For example:

Set oAppEvents = Nothing

After that you won't get the OnDocumentChange event anymore. This can be
done with any object that supports events.

Another approach is if there are only certain times you need to react to the
event you can set flags within your application and then within the event
use these flags to determine if you should do anything. For example:

Private Sub oDocEvents_OnChangeSelectSet(...)
If bHandleSelect Then
' Do something in reaction.
End If
End Sub

In this case you're always getting the event, but in cases where you don't
need to do anything you're quickly getting out.
--
Brian Ekins
Autodesk Inventor API

wrote in message news:5140903@discussion.autodesk.com...
Hi, again Brian!

In your last reply you mention "You should also change where you're loading
the form. The OnDocumentChange is not a good place because this event fires
a lot".

Can you give a sample code, where i can see how to make the event to fire
only one time, by document changing?

I´ve been trying to see this in the add-in samples of Inventor, but for a
beginner the code makes me some confusion.

Thanks again for your reply and help.
0 Likes