-
Notifications
You must be signed in to change notification settings - Fork 1
/
Component Creator V111 NXJ - With TeamCenter.vb
1372 lines (1196 loc) · 63.7 KB
/
Component Creator V111 NXJ - With TeamCenter.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
' Written by Tamas Woller - February 2024, V103
' Journal desciption: Automatically create parts by requesting you a main component name. Select solid bodies to create components for.
' Shared on NXJournaling.com
' Written in VB.Net
' Tested on Siemens NX 2212 and 2306, Native and Teamcenter 13
' V100 - Initial Release - January 2024
' V101 - Body flag system Fix
' V103 - Teamcenter Integration & Local Support, Smart Sorting with EasyWeight or NX's built-in material attributes, Metric (Millimeters) and Imperial (Inches) unit support in Material name, WaveLink Option, Flag Created Components Option, Control Numbering Gaps Option and added Configuration Settings
' V105 - Added notes and minor changes in Output Window
' V107 - Update EasyWeight's EW_Body_Weight attribute before sorting
' V109 - Added 'Maybe' to sorting
' V111 - TC with custom numbering
Imports System
Imports NXOpen
Imports System.Collections.Generic
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports System.Windows.Forms
Imports System.Text.RegularExpressions
Module NXJournal
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim theUFSession As NXOpen.UF.UFSession = NXOpen.UF.UFSession.GetUFSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim mainAssembly As Part = If(workPart.ComponentAssembly.RootComponent IsNot Nothing, workPart.ComponentAssembly.RootComponent.Prototype, workPart)
Dim unitString As String = "mm"
Dim displayPart As NXOpen.Part = theSession.Parts.Display
Dim theUI As NXOpen.UI = NXOpen.UI.GetUI()
Dim logicalobjects1() As NXOpen.PDM.LogicalObject = Nothing
Dim logicalobjects2() As NXOpen.PDM.LogicalObject = Nothing
Dim sourceobjects1() As NXOpen.NXObject
Dim selectedObjectName As String
Dim mySelectedObjects As New List(Of DisplayableObject)
Dim lw As ListingWindow = theSession.ListingWindow
Dim nXObject2 As NXOpen.NXObject = Nothing
Dim lldirectoryPath As String
Dim materialName As String
Dim bodyWeight As Double
Dim smartsortingfeature As Boolean
Dim assemblyid As String
'------------------------
' Configuration Settings:
' Default Assembly ID name
Dim defaultassemblyid As String = "MyProject-01"
' WaveLink Feature - True or False
Dim wavelinkfeature As Boolean = True
' Smart Sorting - This feature sorts the selected bodies by their material name in descending order. It first considers the initial numerical value found in the material name before the unit (for example, the "12" in "12mm Plywood"). If no numerical value is present, sorting is done alphabetically. Should multiple bodies share the same material, they are then sorted by weight in descending order.
' You'll receive feedback on Material name and weight, so you understand the order presented.
' If it False, it will preserve the order in which you initially clicked on the bodies for selection. - "True", "False" or "Maybe"
Dim smartsortingfeatureQST As String = "Maybe"
' This setting is particularly useful when utilizing the smart sorting feature, as it helps break down material names into segments for efficient sorting and organization. For instance, a material named '12mm Plywood' would be divided at 'mm', allowing the code to sort solids effectively.
' You can adjust settings for "mm" (Millimeter) and "in" (Inch) to whatever you use to describe your materials based on your preferred unit system. Let's say, you are naming your solid bodies like "3/4 Inch Plywood" - then you would change 'ssunitin' to "Inch".
' The journal handles whole or decimal numbers (e.g., "12", "12.5") and fractions specifically for inches (e.g., "1/2"). It automatically adjusts these values by multiplying them by 25.4 to ensure consistency in sorting, allowing you to safely use any of these variants within the same workflow.
Dim ssunitmm As String = "mm"
Dim ssunitin As String = "in"
' Sorting logic use EasyWeight (True) or NX Built-in Material (False) attributes. - True or False
Dim EasyWeightsortinglogic As Boolean = False
' Default Solid Body Name - Assigns a name to any solid body that lacks one, ensuring all bodies are identifiable.
' You can set these names under Reference Sets.
' If you can't see this folder, click on a empty space in Part Navigator / uncheck Timestamp Order OR File / Utilities / Customer Defaults / Gateway / Part Navigator / Display Reference Sets Folder.
Dim defaultsolidbodyname As String = "PANEL"
' Flag Created Components - To prevent duplicating efforts, this option tags processed solid bodies with a 'Component created' attribute. It's an efficient way to track which bodies have already been processed.
' If you wan't to override this later, simply delete the value of this attribute in Solid body / Properties. - True or False
' Only for EasyWeight users - When you use EW_Material or NX_Material journal, it automatically adds an empty 'Component created' attribute to solid bodies, addressing a discovered issue in version 1.01.
' The issue arises during modeling, particularly when occurrences are created (for example, mirroring a body in NX results in an 'original' solid and a new 'occurrence'). These occurrences inherit the original attributes, including the flags set during component creation. To resolve this, modifications were made to the component creator journals and the material journal. These changes ensure the assignment of a base attribute, which can then be effectively managed in both instances.
' If you have a proper Material licence, and want to use this journal with this function, you can go around the mentioned issue by assigning the attribute to all your solids at first. Select all Solid Body / Properties / New Attribute / Title: Component created, Data Type: String. A more efficient way would be to change your default model template to have this.
Dim setcomponentflag As Boolean = False
' Teamcenter Integration Settings - Determines whether the journal operates locally "False" or integrates with Teamcenter. Selecting "Maybe" prompts a question at the start to finalize this setting, tailoring the journal to your specific workflow needs. - "True", "False" or "Maybe".
' If you are using this locally, you will be prompted at the beginning to specify where you want to save your files. If you leave it empty and hit enter, it will use the specified default directory (lldefaultdirectoryPath).
Dim teamcenterIntegrationQST As String = "False"
' Control Numbering Gaps - Only for Local - This feature enables intelligent handling of component numbering. For instance, if you initially create components numbered 101, 102, 103, 104, and 105, but later delete 101 and 103, activating this option will prioritize filling these gaps with new components before proceeding to increment the numbers. It's an efficient method to maintain a continuous sequence and optimize the utilization of available numbers.
' Remember, when removing components, it's important not only to remove them from the assembly but also to close them using File / Close / Selected Parts. This ensures they are removed from memory as well.
' Additionally, if you are working locally and have saved these parts, you should also delete them from the file system to avoid clutter. - True or False
Dim fillTheGap As Boolean = True
' IMPORTANT! Record a Journal first in - Visual Basic (*.vb) - by Developer / Record with Assemblies / New Component. Complete the entire process of creating a new component, then stop the recording. In your saved file, you'll find the following variants (note that prefixes such as 'tc', 'll', and 'wl' won't be included) - the matching words are highlighted:
' partOperationCreateBuilder1.DEFAULTDESTINATIONFOLDER, fileNew1.TEMPLATEFILENAME, fileNew1.UNITS, fileNew1.RELATIONTYPE, fileNew1.TEMPLATEPRESENTATIONNAME and fileNew1.ITEMTYPE.
' Copy paste the values.
'
' Explanation and ID numbering for First and Second Rounds:
' The journal is prepared to follow two different logics in Teamcenter. Let me know if you have a specific case:
' Situation One: Non-specific numbering, following system sequence.
' Goal: Invoke a substitute ID usable in the journal.
' Example: If a new component ID is 160379, try creating another with a substitute ID of 16000* (modify the last digit to "*"). If Teamcenter generates the next available number from 160000, we have found what we were looking for.
' Settings:
' Dim defaultassemblyid As String = "16000*" ' Set our base or default assembly ID.
' Dim assemblyidQST As Boolean = False ' Set to False as the ID follows the previous number without query.
' Dim tcwithtworounds as Boolean = False ' The base - 160000 - is already created, so the first round is unnecessary. Only the second round will use the default ID as a wildcard.
' Dim tcfirstround as String = "" ' Not relevant as the first round is skipped.
' Dim tcsecondround as String = "" ' Should be empty since the default ID is set initially.
' Situation Two: Specific assembly numbers are needed, similar to local logic.
' Goal: Invoke a substitute ID usable in the journal.
' Example: After creating and saving "X184-500-101" as the first component, attempt the next one with "X184-500-10*". If TC automatically generates the next number from 101, it's successful.
' Settings:
' Dim defaultassemblyid As String = "MyProject-01" ' Not relevant here since input is always requested.
' Dim assemblyidQST As Boolean = True ' Set to True to always ask for the base specific assembly ID number on each run. Input example: X184-500.
' Dim tcwithtworounds as Boolean = True ' TC requires a base number to be SAVED first (X184-500-101), allowing it to automatically generate subsequent numbers and create follow-up components in the second. (X184-500-102, etc.).
' Dim tcfirstround as String = "-101" ' This is the number appended to the first round.
' Dim tcsecondround as String = "-10*" ' This is the number appended to the second round.
' TC Settings
Dim tcDefaultDestinationFolder As String = ":NewFolder"
Dim tcTemplateFileName As String = "@DB/GT_mm_template/01"
Dim tcUnits As NXOpen.Part.Units = NXOpen.Part.Units.Millimeters
Dim tcRelationType As String = "master"
Dim tcTemplatePresentationName As String = "Model"
Dim tcItemType As String = "Item"
Dim assemblyidQST As Boolean = True
Dim tcwithtworounds as Boolean = True
Dim tcfirstround as String = "-101"
Dim tcsecondround as String = "-10*"
' Local Settings
Dim llTemplateFileName As String = "model-plain-1-mm-template.prt"
Dim llUnits As NXOpen.Part.Units = NXOpen.Part.Units.Millimeters
Dim llTemplatePresentationName As String = "Model"
Dim lldefaultdirectoryPath As String = "C:\NXPartsFolder\"
Dim llnextAvailableId As Integer = 101
' WaveLink Settings
Dim wlAssociative As Boolean = True
Dim wlFixAtCurrentTimestamp As Boolean = False
Dim wlHideOriginal As Boolean = True
Dim wlInheritDisplayProperties As Boolean = True
Dim wlMakePositionIndependent As Boolean = True
Dim wlCopyThreads As Boolean = True
'------------------------
Sub Main(ByVal args() As String)
lw.Open()
theSession = Session.GetSession()
theUFSession = UFSession.GetUFSession()
workPart = theSession.Parts.Work
displayPart = theSession.Parts.Display
theUI = UI.GetUI()
Dim isFirstSave As Boolean = True
lw.WriteLine("------------------------------------------------------------")
lw.WriteLine("Captain Hook's Component Creator Version: 1.11 NXJ ")
lw.WriteLine(" ")
lw.WriteLine("--------------------------------")
lw.WriteLine("Configuration Settings Overview:")
lw.WriteLine(" ")
lw.WriteLine(" - WaveLink Feature: " & If(wavelinkfeature, "Yes", "No"))
If smartsortingfeatureQST IsNot Nothing AndAlso (smartsortingfeatureQST.Equals("True", StringComparison.OrdinalIgnoreCase) OrElse smartsortingfeatureQST.Equals("False", StringComparison.OrdinalIgnoreCase)) Then
smartsortingfeature = Boolean.Parse(smartsortingfeatureQST)
Else
Dim userResponse As DialogResult = MessageBox.Show("Do you wish to enable Smart Sorting for Components?", "Smart Sorting", MessageBoxButtons.YesNoCancel)
Select Case userResponse
Case DialogResult.Yes
smartsortingfeature = True
Case DialogResult.No
smartsortingfeature = False
Case DialogResult.Cancel
lw.WriteLine(" ")
lw.WriteLine("Abandon ship! We're departing the logbook.")
Return
End Select
End If
lw.WriteLine(" - Smart Sorting: " & If(smartsortingfeature, "Yes", "No"))
If smartsortingfeature Then
If EasyWeightsortinglogic Then
lw.WriteLine(" With EasyWeight attributes")
Else
lw.WriteLine(" With NX Built-in attributes")
End If
Else
lw.WriteLine(" Follow the selection order")
End If
lw.WriteLine(" - Component Created flag: " & If(setcomponentflag, "Yes", "No"))
Dim teamcenterIntegration As Boolean = False
If teamcenterIntegrationQST IsNot Nothing AndAlso (teamcenterIntegrationQST.Equals("True", StringComparison.OrdinalIgnoreCase) OrElse teamcenterIntegrationQST.Equals("False", StringComparison.OrdinalIgnoreCase)) Then
teamcenterIntegration = Boolean.Parse(teamcenterIntegrationQST)
Else
Dim userResponse As DialogResult = MessageBox.Show("Are you working with Teamcenter?", "Teamcenter Integration", MessageBoxButtons.YesNoCancel)
Select Case userResponse
Case DialogResult.Yes
teamcenterIntegration = True
Case DialogResult.No
teamcenterIntegration = False
Case DialogResult.Cancel
lw.WriteLine(" ")
lw.WriteLine("Abandon ship! We're departing the logbook.")
Return
End Select
End If
lw.WriteLine(" - Teamcenter integration: " & If(teamcenterIntegration, "Yes", "No"))
If Not teamcenterIntegration Then
Dim userInput As String = InputBox("Where would you like to save your files? - etc. C:\NXPartsFolder\", "Directory Path")
lldirectoryPath = If(String.IsNullOrWhiteSpace(userInput), lldefaultdirectoryPath, userInput)
If Not lldirectoryPath.EndsWith("\") Then
lldirectoryPath &= "\"
End If
' Check if the directory exists
If Not System.IO.Directory.Exists(lldirectoryPath) Then
Try
System.IO.Directory.CreateDirectory(lldirectoryPath)
lw.WriteLine(" Folder has been created. ")
Catch ex As UnauthorizedAccessException
lw.WriteLine(" ")
lw.WriteLine("Stop the presses! Permission to construct the Folder be refused: " & lldirectoryPath)
lw.WriteLine("Pirate's Proclamation: " & ex.Message)
Return
Catch ex As System.IO.PathTooLongException
lw.WriteLine(" ")
lw.WriteLine("Arr, the map stretches further than the eye can see: " & lldirectoryPath)
lw.WriteLine("Pirate's Proclamation: " & ex.Message)
Return
Catch ex As Exception
lw.WriteLine(" ")
lw.WriteLine("Alas, the winds are not in our favor to form the specified Folder: " & lldirectoryPath)
lw.WriteLine("Pirate's Proclamation: " & ex.Message)
Return
End Try
End If
End If
' Perform the unit check on the main assembly
If mainAssembly.PartUnits = BasePart.Units.Inches Then
unitString = "in"
lw.WriteLine(" - Main Assembly Unit System: Imperial (Inches)")
Else
unitString = "mm"
lw.WriteLine(" - Main Assembly Unit System: Metric (Millimeters)")
End If
If Not teamcenterIntegration Then
lw.WriteLine(" - Save to: " & lldirectoryPath)
lw.WriteLine(" - Fill the gaps in numbers: " & If(fillTheGap, "Yes", "No"))
End If
lw.WriteLine(" - Default Solid Body name: " & defaultsolidbodyname)
If assemblyidQST Then
assemblyid = InputBox("Please enter your required ID Name - etc. MyProject-01", "Component Creator")
If String.IsNullOrEmpty(assemblyid) Then
If Not teamcenterIntegration Then
assemblyid = defaultassemblyid
Else
lw.WriteLine(" ")
lw.WriteLine("Abandon ship! We're departing the logbook.")
Exit Sub
End If
End If
Else
assemblyid = defaultassemblyid
End If
lw.WriteLine(" - Base of AssemblyID: " & assemblyid)
lw.WriteLine("---------------------")
lw.WriteLine(" ")
selectedObjectName = SelectObjects("Hey, select multiple somethings", mySelectedObjects)
Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Component Creator")
Dim nXObject1 As NXOpen.NXObject = Nothing
Dim mySolid As New List(Of Body)
Dim baseAssemblyId As String = assemblyid & "-"
Dim idPart As Integer
Dim usedIds As New SortedSet(Of Integer)()
If Not teamcenterIntegration Then
' Get the IDs from existing files in the directory
For Each file As String In System.IO.Directory.GetFiles(lldirectoryPath, baseAssemblyId & "*")
Dim fileName As String = System.IO.Path.GetFileNameWithoutExtension(file)
If fileName.StartsWith(baseAssemblyId) Then
Dim idString As String = fileName.Substring(baseAssemblyId.Length).TrimStart("-"c)
Dim parts As String() = idString.Split("-"c)
If parts.Length > 0 AndAlso Integer.TryParse(parts(0), idPart) Then
usedIds.Add(idPart)
End If
End If
Next
' Get the IDs from components in the NX session that haven't been saved yet
If workPart.ComponentAssembly.RootComponent IsNot Nothing Then
For Each comp As Component In workPart.ComponentAssembly.RootComponent.GetChildren()
Dim compName As String = comp.DisplayName
If compName.StartsWith(baseAssemblyId) Then
Dim idString As String = compName.Substring(baseAssemblyId.Length).TrimStart("-"c)
Dim parts As String() = idString.Split("-"c)
If parts.Length > 0 AndAlso Integer.TryParse(parts(0), idPart) Then
usedIds.Add(idPart)
End If
End If
Next
End If
' Find the first available ID (filling in the gaps)
If fillTheGap Then
While usedIds.Contains(llnextAvailableId)
llnextAvailableId += 1
End While
Else
' If not filling the gap, find the highest ID and add 1
If usedIds.Count > 0 Then
llnextAvailableId = usedIds.Max + 1
End If
End If
End If
For Each tempComp As DisplayableObject In mySelectedObjects
mySolid.Add(CType(tempComp, Body))
Dim attributePropertiesBuilder1 As NXOpen.AttributePropertiesBuilder = Nothing
Dim createNewComponentBuilder1 As NXOpen.Assemblies.CreateNewComponentBuilder = Nothing
Dim AssemblyidString As String = assemblyid & tcfirstround
Dim body As Body = CType(tempComp, Body)
selectedObjectName = body.Name
If setcomponentflag Then
If IsComponentCreated(body) Then
lw.WriteLine(" ")
lw.WriteLine(" - This solid body already has a component: " & selectedObjectName)
Continue For
End If
End If
If String.IsNullOrEmpty(selectedObjectName) Then
Continue For
End If
If teamcenterIntegration Then
If tcwithtworounds Then
Try
Dim fileNew1 As NXOpen.FileNew = theSession.Parts.FileNew()
Dim partOperationCreateBuilder1 As NXOpen.PDM.PartOperationCreateBuilder = Nothing
partOperationCreateBuilder1 = theSession.PdmSession.CreateCreateOperationBuilder(NXOpen.PDM.PartOperationBuilder.OperationType.Create)
fileNew1.SetPartOperationCreateBuilder(partOperationCreateBuilder1)
partOperationCreateBuilder1.SetOperationSubType(NXOpen.PDM.PartOperationCreateBuilder.OperationSubType.FromTemplate)
partOperationCreateBuilder1.SetModelType("master")
partOperationCreateBuilder1.SetItemType("Item")
partOperationCreateBuilder1.CreateLogicalObjects(logicalobjects1)
sourceobjects1 = logicalobjects1(0).GetUserAttributeSourceObjects()
partOperationCreateBuilder1.DefaultDestinationFolder = tcDefaultDestinationFolder
fileNew1.TemplateFileName = tcTemplateFileName
fileNew1.Units = tcUnits
fileNew1.RelationType = tcRelationType
fileNew1.TemplatePresentationName = tcTemplatePresentationName
fileNew1.ItemType = tcItemType
fileNew1.UseBlankTemplate = False
fileNew1.ApplicationName = "ModelTemplate"
fileNew1.UsesMasterModel = "No"
fileNew1.TemplateType = NXOpen.FileNewTemplateType.Item
fileNew1.Specialization = ""
fileNew1.SetCanCreateAltrep(False)
partOperationCreateBuilder1.SetAddMaster(False)
partOperationCreateBuilder1.CreateLogicalObjects(logicalobjects2)
partOperationCreateBuilder1.SetAddMaster(False)
Dim nullNXOpen_BasePart As NXOpen.BasePart = Nothing
Dim objects1(-1) As NXOpen.NXObject
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(nullNXOpen_BasePart, objects1, NXOpen.AttributePropertiesBuilder.OperationType.Create)
Dim objects2(-1) As NXOpen.NXObject
attributePropertiesBuilder1.SetAttributeObjects(objects2)
Dim objects3(0) As NXOpen.NXObject
objects3(0) = sourceobjects1(0)
attributePropertiesBuilder1.SetAttributeObjects(objects3)
attributePropertiesBuilder1.Title = "DB_PART_NO"
attributePropertiesBuilder1.Category = "Item"
attributePropertiesBuilder1.StringValue = AssemblyidString
attributePropertiesBuilder1.Category = "Item"
Dim changed1 As Boolean = Nothing
changed1 = attributePropertiesBuilder1.CreateAttribute()
Dim attributetitles1(-1) As String
Dim titlepatterns1(-1) As String
nXObject1 = partOperationCreateBuilder1.CreateAttributeTitleToNamingPatternMap(attributetitles1, titlepatterns1)
Dim objects4(0) As NXOpen.NXObject
objects4(0) = logicalobjects1(0)
Dim properties1(0) As NXOpen.NXObject
properties1(0) = nXObject1
Dim errorList1 As NXOpen.ErrorList = Nothing
errorList1 = partOperationCreateBuilder1.AutoAssignAttributesWithNamingPattern(objects4, properties1)
errorList1.Dispose()
attributePropertiesBuilder1.Title = "DB_PART_NAME"
attributePropertiesBuilder1.StringValue = selectedObjectName
attributePropertiesBuilder1.Category = "Item"
Dim changed2 As Boolean = Nothing
changed2 = attributePropertiesBuilder1.CreateAttribute()
fileNew1.MasterFileName = ""
fileNew1.MakeDisplayedPart = False
fileNew1.DisplayPartOption = NXOpen.DisplayPartOption.AllowAdditional
partOperationCreateBuilder1.ValidateLogicalObjectsToCommit()
Dim logicalobjects4(0) As NXOpen.PDM.LogicalObject
logicalobjects4(0) = logicalobjects1(0)
partOperationCreateBuilder1.CreateSpecificationsForLogicalObjects(logicalobjects4)
' Create new component
createNewComponentBuilder1 = workPart.AssemblyManager.CreateNewComponentBuilder()
createNewComponentBuilder1.ReferenceSetName = "MODEL"
createNewComponentBuilder1.ComponentOrigin = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentOriginType.Absolute
createNewComponentBuilder1.OriginalObjectsDeleted = False
createNewComponentBuilder1.ObjectForNewComponent.Clear()
'Non Wavelink add body
If Not wavelinkfeature Then
createNewComponentBuilder1.ObjectForNewComponent.Add(body)
'lw.WriteLine(" Solid body added successfully.")
End If
createNewComponentBuilder1.NewFile = fileNew1
Dim nXObject2 As NXOpen.NXObject = Nothing
nXObject2 = createNewComponentBuilder1.Commit()
lw.WriteLine("")
lw.WriteLine(" - First component for: " & selectedObjectName & " created.")
Dim bodyToAdd As NXOpen.Body = CType(body, NXOpen.Body)
If smartsortingfeature Then
If EasyWeightsortinglogic Then
Try
materialName = bodyToAdd.GetStringAttribute("EW_Material")
Catch exInner As Exception
materialName = "Not specified"
End Try
Try
bodyWeight = bodyToAdd.GetRealAttribute("EW_Body_Weight")
Catch exInner As Exception
bodyWeight = -1
End Try
Else
Try
materialName = GetMaterialName(bodyToAdd)
Catch exInner As Exception
materialName = "Not specified"
End Try
Try
bodyWeight = GetBodyWeight(bodyToAdd)
Catch exInner As Exception
bodyWeight = -1
End Try
End If
lw.WriteLine(String.Format(" Material Name: {0}", materialName))
lw.WriteLine(String.Format(" Weight: {0}", bodyWeight.ToString()))
End If
Dim newComponent As NXOpen.Assemblies.Component = TryCast(nXObject2, NXOpen.Assemblies.Component)
Dim newComponentPart As Part = CType(newComponent.Prototype, Part)
If wavelinkfeature Then
' Change the work part to the new component's part
theSession.Parts.SetWork(newComponentPart)
' Setup the WaveLinkBuilder in the new component's context
Dim waveLinkBuilder As Features.WaveLinkBuilder = newComponentPart.BaseFeatures.CreateWaveLinkBuilder(Nothing)
waveLinkBuilder.Type = Features.WaveLinkBuilder.Types.BodyLink
waveLinkBuilder.CopyThreads = False
Dim extractFaceBuilder As Features.ExtractFaceBuilder = waveLinkBuilder.ExtractFaceBuilder
extractFaceBuilder.FaceOption = Features.ExtractFaceBuilder.FaceOptionType.FaceChain
extractFaceBuilder.ParentPart = Features.ExtractFaceBuilder.ParentPartType.OtherPart
extractFaceBuilder.Associative = wlAssociative
extractFaceBuilder.FixAtCurrentTimestamp = wlFixAtCurrentTimestamp
extractFaceBuilder.HideOriginal = wlHideOriginal
extractFaceBuilder.InheritDisplayProperties = wlInheritDisplayProperties
extractFaceBuilder.MakePositionIndependent = wlMakePositionIndependent
extractFaceBuilder.CopyThreads = wlCopyThreads
Dim selectObjectList As SelectObjectList = extractFaceBuilder.BodyToExtract
selectObjectList.Add(body)
waveLinkBuilder.Commit()
lw.WriteLine(" WaveLink added successfully.")
waveLinkBuilder.Destroy()
End If
' Mark the original body as processed
If setcomponentflag Then
SetComponentCreated(body, True)
End If
theSession.Parts.SetWork(workPart)
If isFirstSave Then
Dim partSaveStatus As NXOpen.PartSaveStatus = Nothing
Dim newPart As NXOpen.Part = CType(newComponent.Prototype, NXOpen.Part)
Try
partSaveStatus = newPart.Save(NXOpen.BasePart.SaveComponents.False, NXOpen.BasePart.CloseAfterSave.False)
Catch ex As NXOpen.NXException
Catch ex As Exception
End Try
If partSaveStatus IsNot Nothing Then
partSaveStatus.Dispose()
End If
lw.WriteLine(" Saved to Teamcenter: " & AssemblyidString)
'lw.WriteLine(" ")
'lw.WriteLine("A friendly nudge: the remaining components are still drifting in the digital")
'lw.WriteLine("ether, unsaved. Do cast an eye, delete, if the stars are out of alignment,")
'lw.WriteLine("and proceed as the universe dictates.")
isFirstSave = False
Else
End If
Catch ex As Exception When ex.Message.Contains("The new filename is not a valid file specification")
Dim markId2 As NXOpen.Session.UndoMarkId
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Component Creator")
AssemblyidString = assemblyid & tcsecondround
Dim fileNew1 As NXOpen.FileNew = theSession.Parts.FileNew()
Dim partOperationCreateBuilder1 As NXOpen.PDM.PartOperationCreateBuilder = Nothing
partOperationCreateBuilder1 = theSession.PdmSession.CreateCreateOperationBuilder(NXOpen.PDM.PartOperationBuilder.OperationType.Create)
fileNew1.SetPartOperationCreateBuilder(partOperationCreateBuilder1)
partOperationCreateBuilder1.SetOperationSubType(NXOpen.PDM.PartOperationCreateBuilder.OperationSubType.FromTemplate)
partOperationCreateBuilder1.SetModelType("master")
partOperationCreateBuilder1.SetItemType("Item")
partOperationCreateBuilder1.CreateLogicalObjects(logicalobjects1)
sourceobjects1 = logicalobjects1(0).GetUserAttributeSourceObjects()
partOperationCreateBuilder1.DefaultDestinationFolder = tcDefaultDestinationFolder
fileNew1.TemplateFileName = tcTemplateFileName
fileNew1.Units = tcUnits
fileNew1.RelationType = tcRelationType
fileNew1.TemplatePresentationName = tcTemplatePresentationName
fileNew1.ItemType = tcItemType
fileNew1.UseBlankTemplate = False
fileNew1.ApplicationName = "ModelTemplate"
fileNew1.UsesMasterModel = "No"
fileNew1.TemplateType = NXOpen.FileNewTemplateType.Item
fileNew1.Specialization = ""
fileNew1.SetCanCreateAltrep(False)
partOperationCreateBuilder1.SetAddMaster(False)
partOperationCreateBuilder1.CreateLogicalObjects(logicalobjects2)
partOperationCreateBuilder1.SetAddMaster(False)
Dim nullNXOpen_BasePart As NXOpen.BasePart = Nothing
Dim objects1(-1) As NXOpen.NXObject
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(nullNXOpen_BasePart, objects1, NXOpen.AttributePropertiesBuilder.OperationType.Create)
Dim objects2(-1) As NXOpen.NXObject
attributePropertiesBuilder1.SetAttributeObjects(objects2)
Dim objects3(0) As NXOpen.NXObject
objects3(0) = sourceobjects1(0)
attributePropertiesBuilder1.SetAttributeObjects(objects3)
attributePropertiesBuilder1.Title = "DB_PART_NO"
attributePropertiesBuilder1.Category = "Item"
attributePropertiesBuilder1.StringValue = AssemblyidString
attributePropertiesBuilder1.Category = "Item"
Dim changed1 As Boolean = Nothing
changed1 = attributePropertiesBuilder1.CreateAttribute()
Dim attributetitles1(-1) As String
Dim titlepatterns1(-1) As String
nXObject1 = partOperationCreateBuilder1.CreateAttributeTitleToNamingPatternMap(attributetitles1, titlepatterns1)
Dim objects4(0) As NXOpen.NXObject
objects4(0) = logicalobjects1(0)
Dim properties1(0) As NXOpen.NXObject
properties1(0) = nXObject1
Dim errorList1 As NXOpen.ErrorList = Nothing
errorList1 = partOperationCreateBuilder1.AutoAssignAttributesWithNamingPattern(objects4, properties1)
errorList1.Dispose()
attributePropertiesBuilder1.Title = "DB_PART_NAME"
attributePropertiesBuilder1.StringValue = selectedObjectName
attributePropertiesBuilder1.Category = "Item"
Dim changed2 As Boolean = Nothing
changed2 = attributePropertiesBuilder1.CreateAttribute()
fileNew1.MasterFileName = ""
fileNew1.MakeDisplayedPart = False
fileNew1.DisplayPartOption = NXOpen.DisplayPartOption.AllowAdditional
partOperationCreateBuilder1.ValidateLogicalObjectsToCommit()
Dim logicalobjects4(0) As NXOpen.PDM.LogicalObject
logicalobjects4(0) = logicalobjects1(0)
partOperationCreateBuilder1.CreateSpecificationsForLogicalObjects(logicalobjects4)
createNewComponentBuilder1 = workPart.AssemblyManager.CreateNewComponentBuilder()
createNewComponentBuilder1.ReferenceSetName = "MODEL"
createNewComponentBuilder1.ComponentOrigin = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentOriginType.Absolute
createNewComponentBuilder1.OriginalObjectsDeleted = False
createNewComponentBuilder1.ObjectForNewComponent.Clear()
'Non Wavelink add body
If Not wavelinkfeature Then
createNewComponentBuilder1.ObjectForNewComponent.Add(body)
'lw.WriteLine(" Solid body added successfully.")
End If
createNewComponentBuilder1.NewFile = fileNew1
Dim nXObject2 As NXOpen.NXObject = Nothing
nXObject2 = createNewComponentBuilder1.Commit()
lw.WriteLine(" ")
lw.WriteLine(" - Component created for: " & selectedObjectName)
Dim bodyToAdd As NXOpen.Body = CType(body, NXOpen.Body)
If smartsortingfeature Then
If EasyWeightsortinglogic Then
Try
materialName = bodyToAdd.GetStringAttribute("EW_Material")
Catch exInner As Exception
materialName = "Not specified"
End Try
Try
bodyWeight = bodyToAdd.GetRealAttribute("EW_Body_Weight")
Catch exInner As Exception
bodyWeight = -1
End Try
Else
Try
materialName = GetMaterialName(bodyToAdd)
Catch exInner As Exception
materialName = "Not specified"
End Try
Try
bodyWeight = GetBodyWeight(bodyToAdd)
Catch exInner As Exception
bodyWeight = -1
End Try
End If
lw.WriteLine(String.Format(" Material Name: {0}", materialName))
lw.WriteLine(String.Format(" Weight: {0}", bodyWeight.ToString()))
End If
Dim newComponent As NXOpen.Assemblies.Component = TryCast(nXObject2, NXOpen.Assemblies.Component)
Dim newComponentPart As Part = CType(newComponent.Prototype, Part)
If wavelinkfeature Then
' Change the work part to the new component's part
theSession.Parts.SetWork(newComponentPart)
' Setup the WaveLinkBuilder in the new component's context
Dim waveLinkBuilder As Features.WaveLinkBuilder = newComponentPart.BaseFeatures.CreateWaveLinkBuilder(Nothing)
waveLinkBuilder.Type = Features.WaveLinkBuilder.Types.BodyLink
Dim extractFaceBuilder As Features.ExtractFaceBuilder = waveLinkBuilder.ExtractFaceBuilder
extractFaceBuilder.FaceOption = Features.ExtractFaceBuilder.FaceOptionType.FaceChain
extractFaceBuilder.ParentPart = Features.ExtractFaceBuilder.ParentPartType.OtherPart
extractFaceBuilder.Associative = wlAssociative
extractFaceBuilder.FixAtCurrentTimestamp = wlFixAtCurrentTimestamp
extractFaceBuilder.HideOriginal = wlHideOriginal
extractFaceBuilder.InheritDisplayProperties = wlInheritDisplayProperties
extractFaceBuilder.MakePositionIndependent = wlMakePositionIndependent
extractFaceBuilder.CopyThreads = wlCopyThreads
Dim selectObjectList As SelectObjectList = extractFaceBuilder.BodyToExtract
selectObjectList.Add(body)
waveLinkBuilder.Commit()
lw.WriteLine(" WaveLink added successfully.")
waveLinkBuilder.Destroy()
End If
If setcomponentflag Then
SetComponentCreated(body, True)
End If
theSession.Parts.SetWork(workPart)
Catch ex As Exception
lw.WriteLine(" ")
lw.WriteLine("Yo ho, mates, we've hit a snag... an error has marooned us: " & ex.Message)
lw.WriteLine("Pirate's Proclamation: " & ex.StackTrace)
Finally
If createNewComponentBuilder1 IsNot Nothing Then
createNewComponentBuilder1.Destroy()
End If
If attributePropertiesBuilder1 IsNot Nothing Then
attributePropertiesBuilder1.Destroy()
End If
End Try
Else
Try
Dim markId2 As NXOpen.Session.UndoMarkId
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Component Creator")
AssemblyidString = assemblyid & tcsecondround
Dim fileNew1 As NXOpen.FileNew = theSession.Parts.FileNew()
Dim partOperationCreateBuilder1 As NXOpen.PDM.PartOperationCreateBuilder = Nothing
partOperationCreateBuilder1 = theSession.PdmSession.CreateCreateOperationBuilder(NXOpen.PDM.PartOperationBuilder.OperationType.Create)
fileNew1.SetPartOperationCreateBuilder(partOperationCreateBuilder1)
partOperationCreateBuilder1.SetOperationSubType(NXOpen.PDM.PartOperationCreateBuilder.OperationSubType.FromTemplate)
partOperationCreateBuilder1.SetModelType("master")
partOperationCreateBuilder1.SetItemType("Item")
partOperationCreateBuilder1.CreateLogicalObjects(logicalobjects1)
sourceobjects1 = logicalobjects1(0).GetUserAttributeSourceObjects()
partOperationCreateBuilder1.DefaultDestinationFolder = tcDefaultDestinationFolder
fileNew1.TemplateFileName = tcTemplateFileName
fileNew1.Units = tcUnits
fileNew1.RelationType = tcRelationType
fileNew1.TemplatePresentationName = tcTemplatePresentationName
fileNew1.ItemType = tcItemType
fileNew1.UseBlankTemplate = False
fileNew1.ApplicationName = "ModelTemplate"
fileNew1.UsesMasterModel = "No"
fileNew1.TemplateType = NXOpen.FileNewTemplateType.Item
fileNew1.Specialization = ""
fileNew1.SetCanCreateAltrep(False)
partOperationCreateBuilder1.SetAddMaster(False)
partOperationCreateBuilder1.CreateLogicalObjects(logicalobjects2)
partOperationCreateBuilder1.SetAddMaster(False)
Dim nullNXOpen_BasePart As NXOpen.BasePart = Nothing
Dim objects1(-1) As NXOpen.NXObject
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(nullNXOpen_BasePart, objects1, NXOpen.AttributePropertiesBuilder.OperationType.Create)
Dim objects2(-1) As NXOpen.NXObject
attributePropertiesBuilder1.SetAttributeObjects(objects2)
Dim objects3(0) As NXOpen.NXObject
objects3(0) = sourceobjects1(0)
attributePropertiesBuilder1.SetAttributeObjects(objects3)
attributePropertiesBuilder1.Title = "DB_PART_NO"
attributePropertiesBuilder1.Category = "Item"
attributePropertiesBuilder1.StringValue = AssemblyidString
attributePropertiesBuilder1.Category = "Item"
Dim changed1 As Boolean = Nothing
changed1 = attributePropertiesBuilder1.CreateAttribute()
Dim attributetitles1(-1) As String
Dim titlepatterns1(-1) As String
nXObject1 = partOperationCreateBuilder1.CreateAttributeTitleToNamingPatternMap(attributetitles1, titlepatterns1)
Dim objects4(0) As NXOpen.NXObject
objects4(0) = logicalobjects1(0)
Dim properties1(0) As NXOpen.NXObject
properties1(0) = nXObject1
Dim errorList1 As NXOpen.ErrorList = Nothing
errorList1 = partOperationCreateBuilder1.AutoAssignAttributesWithNamingPattern(objects4, properties1)
errorList1.Dispose()
attributePropertiesBuilder1.Title = "DB_PART_NAME"
attributePropertiesBuilder1.StringValue = selectedObjectName
attributePropertiesBuilder1.Category = "Item"
Dim changed2 As Boolean = Nothing
changed2 = attributePropertiesBuilder1.CreateAttribute()
fileNew1.MasterFileName = ""
fileNew1.MakeDisplayedPart = False
fileNew1.DisplayPartOption = NXOpen.DisplayPartOption.AllowAdditional
partOperationCreateBuilder1.ValidateLogicalObjectsToCommit()
Dim logicalobjects4(0) As NXOpen.PDM.LogicalObject
logicalobjects4(0) = logicalobjects1(0)
partOperationCreateBuilder1.CreateSpecificationsForLogicalObjects(logicalobjects4)
createNewComponentBuilder1 = workPart.AssemblyManager.CreateNewComponentBuilder()
createNewComponentBuilder1.ReferenceSetName = "MODEL"
createNewComponentBuilder1.ComponentOrigin = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentOriginType.Absolute
createNewComponentBuilder1.OriginalObjectsDeleted = False
createNewComponentBuilder1.ObjectForNewComponent.Clear()
'Non Wavelink add body
If Not wavelinkfeature Then
createNewComponentBuilder1.ObjectForNewComponent.Add(body)
'lw.WriteLine(" Solid body added successfully.")
End If
createNewComponentBuilder1.NewFile = fileNew1
Dim nXObject2 As NXOpen.NXObject = Nothing
nXObject2 = createNewComponentBuilder1.Commit()
lw.WriteLine(" ")
lw.WriteLine(" - Component created for: " & selectedObjectName)
Dim bodyToAdd As NXOpen.Body = CType(body, NXOpen.Body)
If smartsortingfeature Then
If EasyWeightsortinglogic Then
Try
materialName = bodyToAdd.GetStringAttribute("EW_Material")
Catch exInner As Exception
materialName = "Not specified"
End Try
Try
bodyWeight = bodyToAdd.GetRealAttribute("EW_Body_Weight")
Catch exInner As Exception
bodyWeight = -1
End Try
Else
Try
materialName = GetMaterialName(bodyToAdd)
Catch exInner As Exception
materialName = "Not specified"
End Try
Try
bodyWeight = GetBodyWeight(bodyToAdd)
Catch exInner As Exception
bodyWeight = -1
End Try
End If
lw.WriteLine(String.Format(" Material Name: {0}", materialName))
lw.WriteLine(String.Format(" Weight: {0}", bodyWeight.ToString()))
End If
Dim newComponent As NXOpen.Assemblies.Component = TryCast(nXObject2, NXOpen.Assemblies.Component)
Dim newComponentPart As Part = CType(newComponent.Prototype, Part)
If wavelinkfeature Then
' Change the work part to the new component's part
theSession.Parts.SetWork(newComponentPart)
' Setup the WaveLinkBuilder in the new component's context
Dim waveLinkBuilder As Features.WaveLinkBuilder = newComponentPart.BaseFeatures.CreateWaveLinkBuilder(Nothing)
waveLinkBuilder.Type = Features.WaveLinkBuilder.Types.BodyLink
Dim extractFaceBuilder As Features.ExtractFaceBuilder = waveLinkBuilder.ExtractFaceBuilder
extractFaceBuilder.FaceOption = Features.ExtractFaceBuilder.FaceOptionType.FaceChain
extractFaceBuilder.ParentPart = Features.ExtractFaceBuilder.ParentPartType.OtherPart
extractFaceBuilder.Associative = wlAssociative
extractFaceBuilder.FixAtCurrentTimestamp = wlFixAtCurrentTimestamp
extractFaceBuilder.HideOriginal = wlHideOriginal
extractFaceBuilder.InheritDisplayProperties = wlInheritDisplayProperties
extractFaceBuilder.MakePositionIndependent = wlMakePositionIndependent
extractFaceBuilder.CopyThreads = wlCopyThreads
Dim selectObjectList As SelectObjectList = extractFaceBuilder.BodyToExtract
selectObjectList.Add(body)
waveLinkBuilder.Commit()
lw.WriteLine(" WaveLink added successfully.")
waveLinkBuilder.Destroy()
End If
' Mark the original body as processed
If setcomponentflag Then
SetComponentCreated(body, True)
End If
theSession.Parts.SetWork(workPart)
Catch ex As Exception
lw.WriteLine(" ")
lw.WriteLine("Yo ho, mates, we've hit a snag... an error has marooned us: " & ex.Message)
lw.WriteLine("Pirate's Proclamation: " & ex.StackTrace)
Finally
If createNewComponentBuilder1 IsNot Nothing Then
createNewComponentBuilder1.Destroy()
End If
If attributePropertiesBuilder1 IsNot Nothing Then
attributePropertiesBuilder1.Destroy()
End If
End Try
End If
Else
' Setup for local (non-Teamcenter) environment
Try
Dim markId2 As NXOpen.Session.UndoMarkId
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Component Creator")
Dim fileNew1 As NXOpen.FileNew = theSession.Parts.FileNew()
' Construct the new file name with the next available ID
Dim newFileName As String = lldirectoryPath & baseAssemblyId & llnextAvailableId.ToString("D3") & "-" & selectedObjectName & ".prt"
Dim simpleFileName As String = baseAssemblyId & llnextAvailableId.ToString("D3") & "-" & selectedObjectName & ".prt"
fileNew1.NewFileName = newFileName
fileNew1.UseBlankTemplate = False
fileNew1.ApplicationName = "ModelTemplate"
fileNew1.Units = llUnits
fileNew1.TemplateType = NXOpen.FileNewTemplateType.Item
fileNew1.TemplatePresentationName = llTemplatePresentationName
fileNew1.AllowTemplatePostPartCreationAction(False)
fileNew1.TemplateFileName = llTemplateFileName
fileNew1.MakeDisplayedPart = False
createNewComponentBuilder1 = workPart.AssemblyManager.CreateNewComponentBuilder()
createNewComponentBuilder1.DefiningObjectsAdded = False
createNewComponentBuilder1.NewComponentName = selectedObjectName.ToString
createNewComponentBuilder1.ReferenceSetName = "MODEL"
createNewComponentBuilder1.OriginalObjectsDeleted = False
createNewComponentBuilder1.DefiningObjectsAdded = True
createNewComponentBuilder1.ComponentOrigin = NXOpen.Assemblies.CreateNewComponentBuilder.ComponentOriginType.Absolute
createNewComponentBuilder1.ObjectForNewComponent.Clear()
createNewComponentBuilder1.NewFile = fileNew1
Dim bodyToAdd As NXOpen.Body = CType(tempComp, NXOpen.Body)
lw.WriteLine(" ")
lw.WriteLine(String.Format(" - Processing Body: " & selectedObjectName))
If smartsortingfeature Then
If EasyWeightsortinglogic Then
Try
materialName = bodyToAdd.GetStringAttribute("EW_Material")
Catch exInner As Exception
materialName = "Not specified"
End Try
Try
bodyWeight = bodyToAdd.GetRealAttribute("EW_Body_Weight")
Catch exInner As Exception
bodyWeight = -1 ' Use -1 or another indicative value to signify that the attribute was not found
End Try
Else
Try
materialName = GetMaterialName(bodyToAdd)
Catch exInner As Exception
materialName = "Not specified"
End Try
Try
bodyWeight = GetBodyWeight(bodyToAdd)
Catch exInner As Exception
bodyWeight = -1 ' Use -1 or another indicative value to signify that the attribute was not found
End Try
End If
lw.WriteLine(String.Format(" Material Name: {0}", materialName))
lw.WriteLine(String.Format(" Weight: {0}", bodyWeight.ToString()))
End If
' Add a selected solid body to the component without Wavelink
If Not wavelinkfeature Then
Dim added1 As Boolean = createNewComponentBuilder1.ObjectForNewComponent.Add(bodyToAdd)
lw.WriteLine(" Solid body added successfully.")
End If
nXObject1 = createNewComponentBuilder1.Commit()
lw.WriteLine(" Component created as: " & simpleFileName)
If wavelinkfeature Then
Dim newComponent As NXOpen.Assemblies.Component = CType(nXObject1, NXOpen.Assemblies.Component)
Dim newComponentPart As NXOpen.Part = CType(newComponent.Prototype, NXOpen.Part)
' Switch to the new component part to work within its context
Dim partLoadStatus As NXOpen.PartLoadStatus = Nothing
theSession.Parts.SetWorkComponent(newComponent, NXOpen.PartCollection.RefsetOption.Current, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus)
If partLoadStatus IsNot Nothing Then partLoadStatus.Dispose()
' Setup the WaveLinkBuilder in the new component's context
Dim waveLinkBuilder As Features.WaveLinkBuilder = newComponentPart.BaseFeatures.CreateWaveLinkBuilder(Nothing)
waveLinkBuilder.Type = Features.WaveLinkBuilder.Types.BodyLink
Dim extractFaceBuilder As Features.ExtractFaceBuilder = waveLinkBuilder.ExtractFaceBuilder
extractFaceBuilder.FaceOption = Features.ExtractFaceBuilder.FaceOptionType.FaceChain
extractFaceBuilder.ParentPart = Features.ExtractFaceBuilder.ParentPartType.OtherPart
extractFaceBuilder.Associative = wlAssociative
extractFaceBuilder.FixAtCurrentTimestamp = wlFixAtCurrentTimestamp
extractFaceBuilder.HideOriginal = wlHideOriginal
extractFaceBuilder.InheritDisplayProperties = wlInheritDisplayProperties
extractFaceBuilder.MakePositionIndependent = wlMakePositionIndependent
extractFaceBuilder.CopyThreads = wlCopyThreads
Dim selectObjectList As SelectObjectList = extractFaceBuilder.BodyToExtract
' Setting up ScCollector and SelectionIntentRule for the body
Dim scCollector As NXOpen.ScCollector = extractFaceBuilder.ExtractBodyCollector
Dim selectionIntentRuleOptions As NXOpen.SelectionIntentRuleOptions = newComponentPart.ScRuleFactory.CreateRuleOptions()
selectionIntentRuleOptions.SetSelectedFromInactive(False)
Dim bodies() As Body = {bodyToAdd}
Dim bodyDumbRule As NXOpen.BodyDumbRule = newComponentPart.ScRuleFactory.CreateRuleBodyDumb(bodies, True, selectionIntentRuleOptions)
selectionIntentRuleOptions.Dispose()
Dim rules() As NXOpen.SelectionIntentRule = {bodyDumbRule}
scCollector.ReplaceRules(rules, False)
waveLinkBuilder.Commit()
lw.WriteLine(" WaveLink added successfully.")
waveLinkBuilder.Destroy()
End If
' Mark the original body as processed
If setcomponentflag Then
SetComponentCreated(body, True)
End If
createNewComponentBuilder1.Destroy()
theSession.CleanUpFacetedFacesAndEdges()
theSession.Parts.SetWork(workPart)
' Add the new ID to the set to track it within the session
usedIds.Add(llnextAvailableId)
' Find the next available ID based on the fillTheGap setting
If fillTheGap Then
llnextAvailableId += 1
While usedIds.Contains(llnextAvailableId)
llnextAvailableId += 1
End While
Else
llnextAvailableId = usedIds.Max + 1
End If
Catch ex As NXOpen.NXException When ex.Message.Contains("File already exists")
lw.WriteLine(" ")
lw.WriteLine("We attempted to fill the gap during component creation, but")
lw.WriteLine("encountered an error because one or more removed parts are still")
lw.WriteLine("in memory. Please close them in the NX session as well.")
lw.WriteLine("Go to File > Close > Selected Parts.")