首页 > Web开发 > 详细

Create PropertyManager Page Example (VB.NET)

时间:2014-05-13 21:00:25      阅读:856      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
  1 SolidWorks API Help
  2 Create PropertyManager Page Example (VB.NET)
  3 This example shows how to create a PropertyManager page that contains two selection boxes, a combo box, 
  4 
  5 and a list box. This example also shows how to handle focus events for these controls. 
  6 
  7  
  8 
  9 NOTE: If the model is an assembly and it contains multiple components and you want to allow the user to 
 10 
 11 select edges, faces, or vertices, then you must specify swSelCOMPSDONTOVERRIDE as an element of 
 12 
 13 SelType for the ISldWorks::SetSelectionFilters method. Otherwise, if the user attempts to select an 
 14 
 15 edge, face, or vertex, then the entire component might get selected and not the edge, face, or vertex. 
 16 
 17 This example demonstrates how to specify the elements for SelType.
 18 
 19  
 20 
 21 ----------------------------------------------------------------------------
 22 
 23  Preconditions: 
 24 
 25  1. Copy Modules - main to your project.
 26 
 27  2. Copy Class Modules - clsPropMgr to a class in your project.
 28 
 29  3. Add the SolidWorks.Interop.swpublished primary interop assembly
 30 
 31     reference to your project (right-click the name of your project, select
 32 
 33     Add Reference, and select SolidWorks.Interop.swpublished on the .NET
 34 
 35     tab.
 36 
 37  4. Ensure that the assembly document opened by the macro exists.
 38 
 39  5. Run the macro to open the assembly document and PropertyManager page.
 40 
 41  42 
 43  Postconditions: 
 44 
 45  A PropertyManager page called Comps is created. Comps contains a selection box 
 46 
 47  where the user‘s selections are shown, a drop-down combo box where Value 2 
 48 
 49  is selected, and a list box where Value 1 is selected. 
 50 
 51  52 
 53  Examine the contents of Comps and the Immediate Window as you 
 54 
 55  perform each of these steps: 
 56 
 57  1. Click a component in the assembly to add to the 
 58 
 59     first selection box. 
 60 
 61  2. Locate, but do not move, the cursor in the graphics area.
 62 
 63  3. Press the right-mouse button.
 64 
 65  4. Click a component in the assembly to add to the second selection box. 
 66 
 67  5. Click Value 4 in the list box at the bottom of Comps. 
 68 
 69  6. Click Value 1 in the list box at the bottom of Comps. 
 70 
 71  7. Click the first selection box. 
 72 
 73  8. Close the PropertyManager page.
 74 
 75   
 76 
 77   NOTES: 
 78 
 79   *  After running this macro, select the
 80 
 81      Tools > Options > System Options > Stop VSTA debugger 
 82 
 83      on macro exit checkbox.
 84 
 85   *  Because the assembly document is used elsewhere, 
 86 
 87      do not save any changes when closing the document.
 88 
 89 ---------------------------------------------------------------------------- 
 90 
 91 Modules - main
 92 
 93 Imports SolidWorks.Interop.sldworks
 94 
 95 Imports SolidWorks.Interop.swconst
 96 
 97 Imports System
 98 
 99  
100 
101 Partial Class SolidWorksMacro
102 
103  
104 
105     Public Part As ModelDoc2
106 
107     Public WithEvents pm As clsPropMgr
108 
109  
110 
111     Sub main()
112 
113  
114 
115         Dim openDocErrors As Long
116 
117         Dim OpenDocWarnings As Long
118 
119  
120 
121         swApp.SetUserPreferenceToggle(swUserPreferenceToggle_e.swStopDebuggingVstaOnExit, False)
122 
123  
124 
125         Part = swApp.OpenDoc6("c:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\advdrawings\bladed shaft.sldasm", swDocumentTypes_e.swDocASSEMBLY, swOpenDocOptions_e.swOpenDocOptions_Silent, "", openDocErrors, OpenDocWarnings)
126 
127  
128 
129         Create a new instance of the PropertyManager class
130 
131         pm = New clsPropMgr(swApp)
132 
133         pm.Show()
134 
135  
136 
137     End Sub      
138 
139  
140 
141     Public swApp As SldWorks
142 
143  
144 
145 End Class
146 
147  
148 
149 Back to top
150 
151 Class Modules - clsPropMgr
152 
153 Imports SolidWorks.Interop.sldworks
154 
155 Imports SolidWorks.Interop.swconst
156 
157 Imports SolidWorks.Interop.swpublished
158 
159 Imports System
160 
161 Imports System.Runtime.InteropServices
162 
163 Imports System.Diagnostics
164 
165  
166 
167 <ComVisibleAttribute(True)> _
168 
169 Public Class clsPropMgr
170 
171  
172 
173     Implements PropertyManagerPage2Handler9
174 
175  
176 
177     Dim swApp As SldWorks
178 
179  
180 
181     General objects required for the PropertyManager page
182 
183     Dim pm_Page As PropertyManagerPage2
184 
185     Dim pm_Group As PropertyManagerPageGroup
186 
187     Dim pm_Selection As PropertyManagerPageSelectionbox
188 
189     Dim pm_Selection2 As PropertyManagerPageSelectionbox
190 
191     Dim pm_Label As PropertyManagerPageLabel
192 
193     Dim pm_Combo As PropertyManagerPageCombobox
194 
195     Dim pm_List As PropertyManagerPageListbox
196 
197  
198 
199     Each object in the page needs a unique ID
200 
201     Const GroupID As Integer = 1
202 
203     Const LabelID As Integer = 2
204 
205     Const SelectionID As Integer = 3
206 
207     Const ComboID As Integer = 4
208 
209     Const ListID As Integer = 5
210 
211     Const Selection2ID As Integer = 6
212 
213  
214 
215     Dim ClickedCancel As Boolean
216 
217     Dim retVal As Integer
218 
219  
220 
221     Sub Show()
222 
223         pm_Page.Show2(0)
224 
225     End Sub
226 
227  
228 
229     The following runs when a new instance
230 
231     of the class is created
232 
233     Public Sub New(ByVal swApp As SldWorks)
234 
235  
236 
237         Dim PageTitle As String
238 
239         Dim caption As String
240 
241         Dim tip As String
242 
243         Dim options As Long
244 
245         Dim longerrors As Long
246 
247         Dim controlType As Integer
248 
249         Dim alignment As Integer
250 
251         Dim listItems(3) As String
252 
253  
254 
255         Set the variables for the page
256 
257         PageTitle = "Comps"
258 
259         options = swPropertyManagerButtonTypes_e.swPropertyManager_OkayButton _
260 
261             + swPropertyManagerButtonTypes_e.swPropertyManager_CancelButton _
262 
263             + swPropertyManagerPageOptions_e.swPropertyManagerOptions_LockedPage _
264 
265             + swPropertyManagerPageOptions_e.swPropertyManagerOptions_PushpinButton
266 
267  
268 
269         Create the PropertyManager page
270 
271         pm_Page = CType(swApp.CreatePropertyManagerPage(PageTitle, _
272 
273             options, Me, longerrors), PropertyManagerPage2)
274 
275  
276 
277         Make sure that the page was created properly
278 
279         If longerrors = swPropertyManagerPageStatus_e.swPropertyManagerPage_Okay Then
280 
281             Begin adding the controls to the page
282 
283  
284 
285             Create the group box
286 
287             caption = "Comps"
288 
289             options = swAddGroupBoxOptions_e.swGroupBoxOptions_Visible + _
290 
291             swAddGroupBoxOptions_e.swGroupBoxOptions_Expanded
292 
293             pm_Group = pm_Page.AddGroupBox(GroupID, caption, options)
294 
295  
296 
297             Create two selection boxes
298 
299             controlType = swPropertyManagerPageControlType_e.swControlType_Selectionbox
300 
301             caption = ""   No caption for selection boxes
302 
303             alignment = swPropertyManagerPageControlLeftAlign_e.swControlAlign_Indent
304 
305             options = swAddControlOptions_e.swControlOptions_Visible + _
306 
307                 swAddControlOptions_e.swControlOptions_Enabled
308 
309             tip = "Select an edge, face, vertex, solid body, or a component"
310 
311             pm_Selection = pm_Group.AddControl(SelectionID, _
312 
313                 controlType, caption, alignment, options, tip)
314 
315             pm_Selection2 = pm_Group.AddControl(Selection2ID, _
316 
317                 controlType, caption, alignment, options, tip)
318 
319             Dim filters(6) As swSelectType_e
320 
321             filters(0) = swSelectType_e.swSelEDGES
322 
323             filters(1) = swSelectType_e.swSelREFEDGES
324 
325             filters(2) = swSelectType_e.swSelFACES
326 
327             filters(3) = swSelectType_e.swSelVERTICES
328 
329             filters(4) = swSelectType_e.swSelSOLIDBODIES
330 
331             filters(5) = swSelectType_e.swSelCOMPONENTS
332 
333             filters(6) = swSelectType_e.swSelCOMPSDONTOVERRIDE
334 
335             Dim filterObj As Object
336 
337             filterObj = filters
338 
339             pm_Selection.SingleEntityOnly = False
340 
341             pm_Selection.AllowMultipleSelectOfSameEntity = True
342 
343             pm_Selection.Height = 50
344 
345             pm_Selection.SetSelectionFilters(filterObj)
346 
347             pm_Selection2.SingleEntityOnly = False
348 
349             pm_Selection2.AllowMultipleSelectOfSameEntity = True
350 
351             pm_Selection2.Height = 50
352 
353             pm_Selection2.SetSelectionFilters(filterObj)
354 
355  
356 
357              Create a combo box
358 
359             controlType = swPropertyManagerPageControlType_e.swControlType_Combobox
360 
361             caption = ""
362 
363             alignment = swPropertyManagerPageControlLeftAlign_e.swControlAlign_Indent
364 
365             options = swAddControlOptions_e.swControlOptions_Visible + _
366 
367                 swAddControlOptions_e.swControlOptions_Enabled
368 
369  
370 
371             tip = "Select a value from the drop-down"
372 
373             pm_Combo = pm_Group.AddControl(ComboID, _
374 
375                 controlType, caption, alignment, options, tip)
376 
377             If Not pm_Combo Is Nothing Then
378 
379                 pm_Combo.Height = 50
380 
381                 listItems(0) = "Value 1"
382 
383                 listItems(1) = "Value 2"
384 
385                 listItems(2) = "Value 3"
386 
387                 listItems(3) = "Value 4"
388 
389                 pm_Combo.AddItems(listItems)
390 
391                 pm_Combo.CurrentSelection = 0
392 
393             End If
394 
395  
396 
397              Create a list box
398 
399             controlType = swPropertyManagerPageControlType_e.swControlType_Listbox
400 
401             caption = ""
402 
403             alignment = swPropertyManagerPageControlLeftAlign_e.swControlAlign_Indent
404 
405             options = swAddControlOptions_e.swControlOptions_Visible + _
406 
407                 swAddControlOptions_e.swControlOptions_Enabled
408 
409             tip = "Multi-select values from the list box"
410 
411             pm_List = pm_Group.AddControl(ListID, _
412 
413                 controlType, caption, alignment, options, tip)
414 
415             pm_List.Style = swPropMgrPageListBoxStyle_e.swPropMgrPageListBoxStyle_MultipleItemSelect
416 
417             pm_List.Height = 50
418 
419             If Not pm_List Is Nothing Then
420 
421                 pm_List.Height = 50
422 
423                 listItems(0) = "Value 1"
424 
425                 listItems(1) = "Value 2"
426 
427                 listItems(2) = "Value 3"
428 
429                 listItems(3) = "Value 4"
430 
431                 pm_List.AddItems(listItems)
432 
433                 pm_List.SetSelectedItem(1, True)
434 
435             End If
436 
437  
438 
439         Else  If the page is not created
440 
441  
442 
443             MsgBox("An error occurred while attempting to create the " _
444 
445                 & "PropertyManager Page", vbCritical)
446 
447  
448 
449         End If
450 
451  
452 
453     End Sub
454 
455  
456 
457     Public Sub AfterActivation() Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.AfterActivation
458 
459     End Sub
460 
461  
462 
463     Public Sub AfterClose() Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.AfterClose
464 
465     End Sub
466 
467  
468 
469     Public Function OnActiveXControlCreated(ByVal Id As Integer, ByVal Status As Boolean) As Integer Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnActiveXControlCreated
470 
471     End Function
472 
473  
474 
475     Public Sub OnButtonPress(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnButtonPress
476 
477     End Sub
478 
479  
480 
481     Public Sub OnCheckboxCheck(ByVal Id As Integer, ByVal Checked As Boolean) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnCheckboxCheck
482 
483     End Sub
484 
485  
486 
487     Public Sub OnClose(ByVal Reason As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnClose
488 
489         If Reason = swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_Cancel Then
490 
491             Cancel button was clicked
492 
493             ClickedCancel = True
494 
495         ElseIf Reason = swPropertyManagerPageCloseReasons_e.swPropertyManagerPageClose_Okay Then
496 
497             OK button was clicked
498 
499             ClickedCancel = False
500 
501         End If
502 
503     End Sub
504 
505  
506 
507     Public Sub OnComboboxEditChanged(ByVal Id As Integer, ByVal Text As String) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnComboboxEditChanged
508 
509     End Sub
510 
511  
512 
513     Public Sub OnComboboxSelectionChanged(ByVal Id As Integer, ByVal Item As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnComboboxSelectionChanged
514 
515     End Sub
516 
517  
518 
519     Public Sub OnGainedFocus(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnGainedFocus
520 
521         Dim varArray As Object
522 
523         Debug.Print("Control box " & Id & " has gained focus")
524 
525         varArray = pm_List.GetSelectedItems
526 
527         pm_Combo.CurrentSelection = varArray(0)
528 
529     End Sub
530 
531  
532 
533     Public Sub OnGroupCheck(ByVal Id As Integer, ByVal Checked As Boolean) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnGroupCheck
534 
535     End Sub
536 
537  
538 
539     Public Sub OnGroupExpand(ByVal Id As Integer, ByVal Expanded As Boolean) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnGroupExpand
540 
541     End Sub
542 
543  
544 
545     Public Function OnHelp() As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnHelp
546 
547     End Function
548 
549  
550 
551     Public Function OnKeystroke(ByVal Wparam As Integer, ByVal Message As Integer, ByVal Lparam As Integer, ByVal Id As Integer) As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnKeystroke
552 
553     End Function
554 
555  
556 
557     Public Sub OnListboxSelectionChanged(ByVal Id As Integer, ByVal Item As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnListboxSelectionChanged
558 
559     End Sub
560 
561  
562 
563     Public Sub OnLostFocus(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnLostFocus
564 
565         Debug.Print("Control box " & Id & " has lost focus")
566 
567     End Sub
568 
569  
570 
571     Public Function OnNextPage() As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnNextPage
572 
573     End Function
574 
575  
576 
577     Public Sub OnNumberboxChanged(ByVal Id As Integer, ByVal Value As Double) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnNumberboxChanged
578 
579     End Sub
580 
581  
582 
583     Public Sub OnOptionCheck(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnOptionCheck
584 
585     End Sub
586 
587  
588 
589     Public Sub OnPopupMenuItem(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnPopupMenuItem
590 
591     End Sub
592 
593  
594 
595     Public Sub OnPopupMenuItemUpdate(ByVal Id As Integer, ByRef retval As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnPopupMenuItemUpdate
596 
597     End Sub
598 
599  
600 
601     Public Function OnPreview() As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnPreview
602 
603     End Function
604 
605  
606 
607     Public Function OnPreviousPage() As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnPreviousPage
608 
609     End Function
610 
611  
612 
613     Public Sub OnRedo() Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnRedo
614 
615     End Sub
616 
617  
618 
619     Public Sub OnSelectionboxCalloutCreated(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSelectionboxCalloutCreated
620 
621     End Sub
622 
623  
624 
625     Public Sub OnSelectionboxCalloutDestroyed(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSelectionboxCalloutDestroyed
626 
627     End Sub
628 
629  
630 
631     Public Sub OnSelectionboxFocusChanged(ByVal Id As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSelectionboxFocusChanged
632 
633         Debug.Print("The focus has moved to selection box " & Id)
634 
635     End Sub
636 
637  
638 
639     Public Sub OnSelectionboxListChanged(ByVal Id As Integer, ByVal Count As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSelectionboxListChanged
640 
641          Move focus to next selection box if right-mouse button pressed
642 
643         pm_Page.SetCursor(swPropertyManagerPageCursors_e.swPropertyManagerPageCursors_Advance)
644 
645         Debug.Print("The list in selection box " & Id & " has changed")
646 
647     End Sub
648 
649  
650 
651     Public Sub OnSliderPositionChanged(ByVal Id As Integer, ByVal Value As Double) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSliderPositionChanged
652 
653     End Sub
654 
655  
656 
657     Public Sub OnSliderTrackingCompleted(ByVal Id As Integer, ByVal Value As Double) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSliderTrackingCompleted
658 
659     End Sub
660 
661  
662 
663     Public Function OnSubmitSelection(ByVal Id As Integer, ByVal Selection As Object, ByVal SelType As Integer, ByRef ItemText As String) As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnSubmitSelection
664 
665         OnSubmitSelection = True
666 
667     End Function
668 
669  
670 
671     Public Function OnTabClicked(ByVal Id As Integer) As Boolean Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnTabClicked
672 
673     End Function
674 
675  
676 
677     Public Sub OnTextboxChanged(ByVal Id As Integer, ByVal Text As String) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnTextboxChanged
678 
679     End Sub
680 
681  
682 
683     Public Sub OnUndo() Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnUndo
684 
685     End Sub
686 
687  
688 
689     Public Sub OnWhatsNew() Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnWhatsNew
690 
691     End Sub
692 
693  
694 
695     Public Sub OnListBoxRMBUp(ByVal Id As Integer, ByVal posX As Integer, ByVal posY As Integer) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnListboxRMBUp
696 
697     End Sub
698 
699 
700     Public Function OnWindowFromHandleControlCreated(ByVal Id As Integer, ByVal Status As Boolean) As Integer Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnWindowFromHandleControlCreated
701 
702     End Function
703 
704  
705 
706     Public Sub OnNumberBoxTrackingCompleted(ByVal Id As Integer, ByVal Value As Double) Implements SolidWorks.Interop.swpublished.IPropertyManagerPage2Handler9.OnNumberBoxTrackingCompleted
707 
708     End Sub
709 
710 End Class
711 

bubuko.com,布布扣

 

Create PropertyManager Page Example (VB.NET),布布扣,bubuko.com

Create PropertyManager Page Example (VB.NET)

原文:http://www.cnblogs.com/frankwu2014/p/3724061.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!