Property manager

vos questions concernant les API SolidWorks

Property manager

Messagepar lajproSW » Mer 24 Fév 2016, 10:15

Bonjour,

J'ai trouvé un exemple dans l'aide API de SW pour créer un propertymanager, je bute sur une erreur 98 me disant "Un appel à une propriété ou une méthode ne peut pas utiliser de référence vers un objet privé...".

J'ai cette erreur à la ligne suivante dans un module de classe :

"Set pm_Page = swApp.CreatePropertyManagerPage(PageTitle, options, Me, longerrors)"

Tous les objets du module ont pourtant été déclarés avant :


'Class Modules - clsPropMgr
Option Explicit
'Required for PropertyManager page controls
Implements PropertyManagerPage2Handler9
'General objects required for the PropertyManager page
Dim pm_Page As PropertyManagerPage2
Dim pm_Group As PropertyManagerPageGroup
Dim pm_Selection As PropertyManagerPageSelectionbox
Dim pm_Selection2 As PropertyManagerPageSelectionbox
Dim pm_Label As PropertyManagerPageLabel
Dim pm_Combo As PropertyManagerPageCombobox
Dim pm_List As PropertyManagerPageListbox"

Je tourne avec solidworks 2012.

Merci.
lajproSW
Ewok SolidWorks
 
Messages: 38
Inscription: Mar 16 Mar 2010, 10:32
Localisation: VALENCE

Re: Property manager

Messagepar CLLC » Ven 26 Fév 2016, 8:04

Bonjour

as tu résolu le problème?

Il faudrait avoir le code entier pour mieux comprendre à mon avis.
CLLC
Padawan SolidWorks
 
Messages: 68
Inscription: Ven 06 Juin 2014, 9:42

Re: Property manager

Messagepar lajproSW » Jeu 03 Mar 2016, 8:48

Bonjour,

Pour l'instant je n'ai pas avancé, voilà le code complet.
Tout le code est issu de l'aide API de solidworks.

Merci.

'--------------------------------------------------------------------------
' Preconditions:
' 1. Copy Modules - main to your project.
' 2. Copy Class Modules - clsPropMgr to a class module in your project.
' 3. Add swpublished.tlb to your project (click Tools > References >
' SolidWorks version exposed type libraries for add-in use).
' 4. Ensure that the assembly document opened by the macro exists.
' 5. Run the macro to open the assembly document and PropertyManager page.
'
' Postconditions:
' A PropertyManager page called Comps is created. Comps
' contains a selection box where the user's selections are shown,
' a drop-down combo box where Value 2 is selected, and a
' list box where Value 1 is selected.
'
' Examine the contents of Comps and the Immediate Window after
' performing each of the following steps:
' 1. Click a component in the assembly to add to the first selection box.
' 2. Observe, but do not move, the cursor.
' 3. Press the right-mouse button.
' 4. Click a component in the assembly to add to the second selection box.
' 5. Click Value 4 in the list box at the bottom of Comps.
' 6. Click Value 1 in the list box at the bottom of Comps.
' 7. Click the first selection box.
' 8. Close the PropertyManager page.
'
' NOTE: Because the assembly document is used elsewhere,
' do not save any changes when closing the document.
'----------------------------------------------------------------------------
'Modules - main

Option Explicit



Public swApp As SldWorks.SldWorks

Public Part As SldWorks.ModelDoc2

Public pm As clsPropMgr



Sub main()

Dim openDocErrors As Long

Dim OpenDocWarnings As Long



Set swApp = Application.SldWorks

Set Part = swApp.OpenDoc6("C:\Program Files\SolidWorks Corp 2012\SolidWorks\samples\tutorial\advdrawings\bladed shaft.sldasm", swDocASSEMBLY, swOpenDocOptions_Silent, "", openDocErrors, OpenDocWarnings)

'Create a new instance of the PropertyManager class

Set pm = New clsPropMgr

pm.Show

End Sub

-------------------------Module de classe-----------------------------

'Class Modules - clsPropMgr

Option Explicit

'Required for PropertyManager page controls

Implements PropertyManagerPage2Handler9

'General objects required for the PropertyManager page

Dim pm_Page As PropertyManagerPage2

Dim pm_Group As PropertyManagerPageGroup

Dim pm_Selection As PropertyManagerPageSelectionbox

Dim pm_Selection2 As PropertyManagerPageSelectionbox

Dim pm_Label As PropertyManagerPageLabel

Dim pm_Combo As PropertyManagerPageCombobox

Dim pm_List As PropertyManagerPageListbox

'Each object in the page needs a unique ID

Const GroupID As Long = 1

Const LabelID As Long = 2

Const SelectionID As Long = 3

Const ComboID As Long = 4

Const ListID As Long = 5

Const Selection2ID As Long = 6


Dim ClickedCancel As Boolean


'Public swApp As SldWorks.SldWorks
'Public pm As clsPropMgr

Dim retVal As Long



Sub Show()

pm_Page.Show2 0

End Sub


'The following runs when a new instance

'of the class is created


Private Sub Class_Initialize()


Dim PageTitle As String

Dim cAption As String

Dim tiP As String

Dim opTions As Long

Dim longErrors As Long

Dim controlType As Long

Dim alignment As Long

Dim listItems(3) As String

'Dim insTance As ISldWorks

'Dim vaLue As Object

'Dim Handler As Object



'Set the variables for the page

PageTitle = "Comps"

opTions = swPropertyManager_OkayButton + swPropertyManager_CancelButton + swPropertyManagerOptions_LockedPage + swPropertyManagerOptions_PushpinButton



'Create the PropertyManager page

Set pm_Page = swApp.CreatePropertyManagerPage(PageTitle, opTions, Me, longErrors)

'vaLue = insTance.CreatePropertyManagerPage("essai", opTions, Handler, longErrors)



'Make sure that the page was created properly

If longErrors = swPropertyManagerPage_Okay Then



'Begin adding the controls to the page



'Create the group box

cAption = "Comps"

opTions = swGroupBoxOptions_Visible + swGroupBoxOptions_Expanded

Set pm_Group = pm_Page.AddGroupBox(GroupID, cAption, opTions)



'Create two selection boxes

controlType = swControlType_Selectionbox

cAption = "" ' No caption for selection boxes

alignment = swControlAlign_Indent

opTions = swControlOptions_Visible + swControlOptions_Enabled

tiP = "Select an edge, face, vertex, solid body, or a component"

Set pm_Selection = pm_Group.AddControl(SelectionID, controlType, cAption, alignment, opTions, tiP)



Set pm_Selection2 = pm_Group.AddControl(Selection2ID, controlType, cAption, alignment, opTions, tiP)

Dim filters(6) As Long

filters(0) = swSelEDGES

filters(1) = swSelREFEDGES

filters(2) = swSelFACES

filters(3) = swSelVERTICES

filters(4) = swSelSOLIDBODIES

filters(5) = swSelCOMPONENTS

filters(6) = swSelCOMPSDONTOVERRIDE

pm_Selection.SingleEntityOnly = False

pm_Selection.AllowMultipleSelectOfSameEntity = True

pm_Selection.Height = 50

pm_Selection.SetSelectionFilters filters



pm_Selection2.SingleEntityOnly = False

pm_Selection2.AllowMultipleSelectOfSameEntity = True

pm_Selection2.Height = 50

pm_Selection2.SetSelectionFilters filters



' Create a combo box

controlType = swControlType_Combobox

cAption = ""

alignment = swControlAlign_Indent

opTions = swControlOptions_Visible + swControlOptions_Enabled

tiP = "Select a value from the dropdown"

Set pm_Combo = pm_Group.AddControl(ComboID, controlType, cAption, alignment, opTions, tiP)



If Not pm_Combo Is Nothing Then

pm_Combo.Height = 50



listItems(0) = "Value 1"

listItems(1) = "Value 2"

listItems(2) = "Value 3"

listItems(3) = "Value 4"



pm_Combo.AddItems (listItems)

pm_Combo.CurrentSelection = 0



End If



' Create a list box

controlType = swControlType_Listbox

cAption = ""

alignment = swControlAlign_Indent

opTions = swControlOptions_Visible + swControlOptions_Enabled

tiP = "Multi-select values from the list box"

Set pm_List = pm_Group.AddControl(ListID, controlType, cAption, alignment, opTions, tiP)



pm_List.Style = swPropMgrPageListBoxStyle_MultipleItemSelect

pm_List.Height = 50



If Not pm_List Is Nothing Then

pm_List.Height = 50



listItems(0) = "Value 1"

listItems(1) = "Value 2"

listItems(2) = "Value 3"

listItems(3) = "Value 4"



pm_List.AddItems (listItems)

pm_List.SetSelectedItem 1, True

End If



Else 'If the page is not created

MsgBox "An error occurred while attempting to create the " & "PropertyManager Page", vbCritical

End If



End Sub



Private Sub PropertyManagerPage2Handler9_AfterActivation()

End Sub



Private Sub PropertyManagerPage2Handler9_AfterClose()

'Destroy the class

Set pm = Nothing

End Sub



Private Function PropertyManagerPage2Handler9_OnActiveXControlCreated(ByVal Id As Long, ByVal Status As Boolean) As Long

End Function



Private Sub PropertyManagerPage2Handler9_OnButtonPress(ByVal Id As Long)

End Sub



Private Sub PropertyManagerPage2Handler9_OnCheckboxCheck(ByVal Id As Long, ByVal Checked As Boolean)

End Sub



Private Sub PropertyManagerPage2Handler9_OnClose(ByVal Reason As Long)

If Reason = swPropertyManagerPageClose_Cancel Then

'Cancel button was clicked

ClickedCancel = True

ElseIf Reason = swPropertyManagerPageClose_Okay Then

'OK button was clicked

ClickedCancel = False

End If

End Sub



Private Sub PropertyManagerPage2Handler9_OnComboboxEditChanged(ByVal Id As Long, ByVal Text As String)

End Sub



Private Sub PropertyManagerPage2Handler9_OnComboboxSelectionChanged(ByVal Id As Long, ByVal Item As Long)

End Sub



Private Sub PropertyManagerPage2Handler9_OnGroupCheck(ByVal Id As Long, ByVal Checked As Boolean)

End Sub



Private Sub PropertyManagerPage2Handler9_OnGroupExpand(ByVal Id As Long, ByVal Expanded As Boolean)

End Sub



Private Function PropertyManagerPage2Handler9_OnHelp() As Boolean

End Function



Private Function PropertyManagerPage2Handler9_OnKeystroke(ByVal Wparam As Long, ByVal Message As Long, ByVal Lparam As Long, ByVal Id As Long) As Boolean

End Function



Private Sub PropertyManagerPage2Handler9_OnListboxSelectionChanged(ByVal Id As Long, ByVal Item As Long)

End Sub



Private Function PropertyManagerPage2Handler9_OnNextPage() As Boolean

End Function



Private Sub PropertyManagerPage2Handler9_OnNumberboxChanged(ByVal Id As Long, ByVal vaLue As Double)

End Sub



Private Sub PropertyManagerPage2Handler9_OnOptionCheck(ByVal Id As Long)

End Sub



Private Sub PropertyManagerPage2Handler9_OnPopupMenuItem(ByVal Id As Long)

End Sub



Private Sub PropertyManagerPage2Handler9_OnPopupMenuItemUpdate(ByVal Id As Long, retVal As Long)

End Sub



Private Function PropertyManagerPage2Handler9_OnPreview() As Boolean

End Function



Private Function PropertyManagerPage2Handler9_OnPreviousPage() As Boolean

End Function



Private Sub PropertyManagerPage2Handler9_OnRedo()

End Sub



Private Sub PropertyManagerPage2Handler9_OnSelectionboxCalloutCreated(ByVal Id As Long)

End Sub



Private Sub PropertyManagerPage2Handler9_OnSelectionboxCalloutDestroyed(ByVal Id As Long)

End Sub



Private Sub PropertyManagerPage2Handler9_OnSelectionboxFocusChanged(ByVal Id As Long)

Debug.Print "The focus has moved to selection box " & Id

End Sub



Private Sub PropertyManagerPage2Handler9_OnSelectionboxListChanged(ByVal Id As Long, ByVal Count As Long)

' Move focus to next selection box if right-mouse button pressed

pm_Page.SetCursor (swPropertyManagerPageCursors_Advance)

Debug.Print "The list in selection box " & Id & " has changed"

End Sub



Private Sub PropertyManagerPage2Handler9_OnSliderPositionChanged(ByVal Id As Long, ByVal vaLue As Double)

End Sub



Private Sub PropertyManagerPage2Handler9_OnSliderTrackingCompleted(ByVal Id As Long, ByVal vaLue As Double)

End Sub



Private Function PropertyManagerPage2Handler9_OnSubmitSelection(ByVal Id As Long, ByVal Selection As Object, ByVal SelType As Long, ItemText As String) As Boolean

PropertyManagerPage2Handler9_OnSubmitSelection = True

End Function



Private Function PropertyManagerPage2Handler9_OnTabClicked(ByVal Id As Long) As Boolean

End Function



Private Sub PropertyManagerPage2Handler9_OnTextboxChanged(ByVal Id As Long, ByVal Text As String)

End Sub



Private Sub PropertyManagerPage2Handler9_OnUndo()

End Sub



Private Sub PropertyManagerPage2Handler9_OnWhatsNew()

End Sub

Private Sub PropertyManagerPage2Handler9_OnLostFocus(ByVal Id As Long)

Debug.Print "Control box " & Id & " has lost focus"

End Sub



Private Sub PropertyManagerPage2Handler9_OnGainedFocus(ByVal Id As Long)

Dim varArray As Variant

Debug.Print "Control box " & Id & " has gained focus"

varArray = pm_List.GetSelectedItems

pm_Combo.CurrentSelection = varArray(0)

End Sub


Public Sub PropertyManagerPage2Handler9_OnListBoxRMBUp(ByVal Id As Long, ByVal posX As Long, ByVal posY As Long)

End Sub


Public Function PropertyManagerPage2Handler9_OnWindowFromHandleControlCreated(ByVal Id As Long, ByVal Status As Boolean) As Long

End Function


Public Sub PropertyManagerPage2Handler9_OnNumberboxTrackingCompleted(ByVal Id As Long, ByVal vaLue As Double)

End Sub
lajproSW
Ewok SolidWorks
 
Messages: 38
Inscription: Mar 16 Mar 2010, 10:32
Localisation: VALENCE

Re: Property manager

Messagepar CLLC » Ven 04 Mar 2016, 9:30

J'ai copié une partie du code dans un module, l'autre partie dans un module de classe que j'ai renommé "clsPropMgr"
J'ai ajouter la référence "SolidWorks 2013 exposed type libraries for add-in use"

Tout marche correctement.

Tu n'as rien changé à ce code là?
Peut être envoie le fichier de ta macro pour mieux voir.
CLLC
Padawan SolidWorks
 
Messages: 68
Inscription: Ven 06 Juin 2014, 9:42

Re: Property manager

Messagepar lajproSW » Ven 11 Mar 2016, 9:56

Bonjour,

Je viens de relancer la macro et miracle ça fonctionne, je l'ai essayé des dizaines de fois avec toujours la même erreur et la tout baigne. Peut-être qu'il n'avait pas chargé et pris en compte la référence ".... exposed type libraries for add-in use" tout de suite.

Merci pour votre réponse.
lajproSW
Ewok SolidWorks
 
Messages: 38
Inscription: Mar 16 Mar 2010, 10:32
Localisation: VALENCE


Retourner vers Questions générales sur les API

 


  • Articles en relation
    Réponses
    Vus
    Dernier message

Qui est en ligne

Utilisateurs parcourant ce forum: Google [Bot] et 4 invités

banniere