StianA
Mechanical
- Nov 7, 2011
- 12
Hi,
I am trying to create a script that changes the settings for Feature Control Frames, Datum feature Symbols, Notes, etc.
I am new to programming and I am not 100% sure of what I'm doing so I could need some help.
So far I have this Code:
-------------------------------------------------------------------------------------------
Option Strict Off
Imports NXOpen
Module set_dim_text_to_arial
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Sub Main()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "change dim text to Arial")
'Declare Font type
Dim fntArial As Integer = workPart.Fonts.AddFont("Arial", FontCollection.Type.Standard)
'Change Feature Control Frame Settings
For Each tempFcF As Annotations.DraftingFcf In workPart.Gdts
Dim symbolPreferences1 As Annotations.SymbolPreferences
symbolPreferences1 = tempFcF.GetSymbolPreferences()
Dim lineAndArrowPreferences1 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences1 = tempFcF.GetLineAndArrowPreferences()
Dim letteringPreferences1 As Annotations.LetteringPreferences
letteringPreferences1 = tempFcF.GetLetteringPreferences()
Dim generalText1 As Annotations.Lettering
generalText1.Size = 3.5
generalText1.CharacterSpaceFactor = 0.0
generalText1.AspectRatio = 0.8
generalText1.LineSpaceFactor = 1.0
generalText1.Cfw.Color = 37
generalText1.Cfw.Font = fntArial
generalText1.Cfw.Width = Annotations.LineWidth.Thin
generalText1.Italic = False
letteringPreferences1.SetGeneralText(generalText1)
tempFcF.SetLetteringPreferences(letteringPreferences1)
letteringPreferences1.Dispose()
lineAndArrowPreferences1.Dispose()
symbolPreferences1.SetWeldSpaceFactor(2.0)
symbolPreferences1.SetWeldSymbolSizeFactor(1.0)
Dim weldSymbolCfw1 As Annotations.LineCfw = New Annotations.LineCfw(37, DisplayableObject.ObjectFont.Solid, Annotations.LineWidth.Thin)
symbolPreferences1.SetWeldSymbolCfw(weldSymbolCfw1)
Dim surfaceFinishCfw1 As Annotations.LineCfw = New Annotations.LineCfw(37, DisplayableObject.ObjectFont.Solid, Annotations.LineWidth.Thin)
symbolPreferences1.SetSurfaceFinishCfw(surfaceFinishCfw1)
symbolPreferences1.DraftingSurfaceFinishStandard = Annotations.SurfaceFinishStandard.Iso2002
symbolPreferences1.WeldSymbolStandard = Annotations.WeldStandard.Iso
tempFcF.SetSymbolPreferences(symbolPreferences1)
symbolPreferences1.Dispose()
tempFcF.LeaderOrientation = Annotations.LeaderOrientation.FromLeft
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
Next
'Change Note Settings
For Each tempNote As Annotations.Note In workPart.Notes
Dim lineAndArrowPreferences1 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences1 = tempNote.GetLineAndArrowPreferences()
Dim letteringPreferences1 As Annotations.LetteringPreferences
letteringPreferences1 = tempNote.GetLetteringPreferences()
Dim generalText1 As Annotations.Lettering
generalText1.Size = 3.5
generalText1.CharacterSpaceFactor = 0.0
generalText1.AspectRatio = 0.8
generalText1.LineSpaceFactor = 1.0
generalText1.Cfw.Color = 37
generalText1.Cfw.Font = fntArial
generalText1.Cfw.Width = Annotations.LineWidth.Thin
generalText1.Italic = False
letteringPreferences1.SetGeneralText(generalText1)
tempNote.SetLetteringPreferences(letteringPreferences1)
letteringPreferences1.Dispose()
lineAndArrowPreferences1.Dispose()
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
Next
'Change Label Settings
For Each tempLabel As Annotations.Label In workPart.Labels
Dim lineAndArrowPreferences1 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences1 = tempLabel.GetLineAndArrowPreferences()
Dim letteringPreferences1 As Annotations.LetteringPreferences
letteringPreferences1 = tempLabel.GetLetteringPreferences()
Dim generalText1 As Annotations.Lettering
generalText1.Size = 3.5
generalText1.CharacterSpaceFactor = 0.0
generalText1.AspectRatio = 0.8
generalText1.LineSpaceFactor = 1.0
generalText1.Cfw.Color = 37
generalText1.Cfw.Font = fntArial
generalText1.Cfw.Width = Annotations.LineWidth.Thin
generalText1.Italic = False
letteringPreferences1.SetGeneralText(generalText1)
tempLabel.SetLetteringPreferences(letteringPreferences1)
letteringPreferences1.Dispose()
lineAndArrowPreferences1.Dispose()
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
Next
'Change Settings for DatumFeatureSymbols
For Each tempDatumFeatureSymbol As Annotations.DraftingDatum In workPart.Gdts
Dim symbolPreferences2 As Annotations.SymbolPreferences
symbolPreferences2 = tempDatumFeatureSymbol.GetSymbolPreferences()
Dim lineAndArrowPreferences1 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences1 = tempDatumFeatureSymbol.GetLineAndArrowPreferences()
Dim letteringPreferences1 As Annotations.LetteringPreferences
letteringPreferences1 = tempDatumFeatureSymbol.GetLetteringPreferences()
Dim generalText2 As Annotations.Lettering
generalText2.Size = 3.5
generalText2.CharacterSpaceFactor = 0.0
generalText2.AspectRatio = 0.8
generalText2.LineSpaceFactor = 1.0
generalText2.Cfw.Color = 37
generalText2.Cfw.Font = fntArial
generalText2.Cfw.Width = Annotations.LineWidth.Thin
generalText2.Italic = False
letteringPreferences1.SetGeneralText(generalText2)
tempDatumFeatureSymbol.SetLetteringPreferences(letteringPreferences1)
letteringPreferences1.Dispose()
lineAndArrowPreferences1.Dispose()
symbolPreferences2.SetWeldSpaceFactor(2.0)
symbolPreferences2.SetWeldSymbolSizeFactor(1.0)
Dim weldSymbolCfw1 As Annotations.LineCfw = New Annotations.LineCfw(37, DisplayableObject.ObjectFont.Solid, Annotations.LineWidth.Thin)
symbolPreferences2.SetWeldSymbolCfw(weldSymbolCfw1)
Dim surfaceFinishCfw1 As Annotations.LineCfw = New Annotations.LineCfw(37, DisplayableObject.ObjectFont.Solid, Annotations.LineWidth.Thin)
symbolPreferences2.SetSurfaceFinishCfw(surfaceFinishCfw1)
symbolPreferences2.DraftingSurfaceFinishStandard = Annotations.SurfaceFinishStandard.Iso2002
symbolPreferences2.WeldSymbolStandard = Annotations.WeldStandard.Iso
tempDatumFeatureSymbol.SetSymbolPreferences(symbolPreferences2)
symbolPreferences2.Dispose()
tempDatumFeatureSymbol.LeaderOrientation = Annotations.LeaderOrientation.FromLeft
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId1)
Next
End Sub
End Module
--------------------------------------------------------------------------------------------
Each section here is working ok, but if I have a drawing that includes both feature control frames and Datum Feature Symbols, it does not work. I think this is because of these lines:
For Each tempFcF As Annotations.DraftingFcf In workPart.Gdts
and this one:
For Each tempDatumFeatureSymbol As Annotations.DraftingDatum In workPart.Gdts
I want to run through all Feature control frames and change the settings for each one. So here I am saving a draftingFcf from workpart.Gdts to tempFcf. Since workpart.Gdts returns both DraftingFcf and
DraftingDatums when the script finds a DraftingDatum and tries to save it as a draftingFcf it crashes.
So my question is how can I search for just DraftingFcfs or just DraftingDatums in my workpart? Or maybe there is a better way of doing this?
Thanks in advance!
Stian L. Amstrup
I am trying to create a script that changes the settings for Feature Control Frames, Datum feature Symbols, Notes, etc.
I am new to programming and I am not 100% sure of what I'm doing so I could need some help.
So far I have this Code:
-------------------------------------------------------------------------------------------
Option Strict Off
Imports NXOpen
Module set_dim_text_to_arial
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Sub Main()
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "change dim text to Arial")
'Declare Font type
Dim fntArial As Integer = workPart.Fonts.AddFont("Arial", FontCollection.Type.Standard)
'Change Feature Control Frame Settings
For Each tempFcF As Annotations.DraftingFcf In workPart.Gdts
Dim symbolPreferences1 As Annotations.SymbolPreferences
symbolPreferences1 = tempFcF.GetSymbolPreferences()
Dim lineAndArrowPreferences1 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences1 = tempFcF.GetLineAndArrowPreferences()
Dim letteringPreferences1 As Annotations.LetteringPreferences
letteringPreferences1 = tempFcF.GetLetteringPreferences()
Dim generalText1 As Annotations.Lettering
generalText1.Size = 3.5
generalText1.CharacterSpaceFactor = 0.0
generalText1.AspectRatio = 0.8
generalText1.LineSpaceFactor = 1.0
generalText1.Cfw.Color = 37
generalText1.Cfw.Font = fntArial
generalText1.Cfw.Width = Annotations.LineWidth.Thin
generalText1.Italic = False
letteringPreferences1.SetGeneralText(generalText1)
tempFcF.SetLetteringPreferences(letteringPreferences1)
letteringPreferences1.Dispose()
lineAndArrowPreferences1.Dispose()
symbolPreferences1.SetWeldSpaceFactor(2.0)
symbolPreferences1.SetWeldSymbolSizeFactor(1.0)
Dim weldSymbolCfw1 As Annotations.LineCfw = New Annotations.LineCfw(37, DisplayableObject.ObjectFont.Solid, Annotations.LineWidth.Thin)
symbolPreferences1.SetWeldSymbolCfw(weldSymbolCfw1)
Dim surfaceFinishCfw1 As Annotations.LineCfw = New Annotations.LineCfw(37, DisplayableObject.ObjectFont.Solid, Annotations.LineWidth.Thin)
symbolPreferences1.SetSurfaceFinishCfw(surfaceFinishCfw1)
symbolPreferences1.DraftingSurfaceFinishStandard = Annotations.SurfaceFinishStandard.Iso2002
symbolPreferences1.WeldSymbolStandard = Annotations.WeldStandard.Iso
tempFcF.SetSymbolPreferences(symbolPreferences1)
symbolPreferences1.Dispose()
tempFcF.LeaderOrientation = Annotations.LeaderOrientation.FromLeft
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
Next
'Change Note Settings
For Each tempNote As Annotations.Note In workPart.Notes
Dim lineAndArrowPreferences1 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences1 = tempNote.GetLineAndArrowPreferences()
Dim letteringPreferences1 As Annotations.LetteringPreferences
letteringPreferences1 = tempNote.GetLetteringPreferences()
Dim generalText1 As Annotations.Lettering
generalText1.Size = 3.5
generalText1.CharacterSpaceFactor = 0.0
generalText1.AspectRatio = 0.8
generalText1.LineSpaceFactor = 1.0
generalText1.Cfw.Color = 37
generalText1.Cfw.Font = fntArial
generalText1.Cfw.Width = Annotations.LineWidth.Thin
generalText1.Italic = False
letteringPreferences1.SetGeneralText(generalText1)
tempNote.SetLetteringPreferences(letteringPreferences1)
letteringPreferences1.Dispose()
lineAndArrowPreferences1.Dispose()
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
Next
'Change Label Settings
For Each tempLabel As Annotations.Label In workPart.Labels
Dim lineAndArrowPreferences1 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences1 = tempLabel.GetLineAndArrowPreferences()
Dim letteringPreferences1 As Annotations.LetteringPreferences
letteringPreferences1 = tempLabel.GetLetteringPreferences()
Dim generalText1 As Annotations.Lettering
generalText1.Size = 3.5
generalText1.CharacterSpaceFactor = 0.0
generalText1.AspectRatio = 0.8
generalText1.LineSpaceFactor = 1.0
generalText1.Cfw.Color = 37
generalText1.Cfw.Font = fntArial
generalText1.Cfw.Width = Annotations.LineWidth.Thin
generalText1.Italic = False
letteringPreferences1.SetGeneralText(generalText1)
tempLabel.SetLetteringPreferences(letteringPreferences1)
letteringPreferences1.Dispose()
lineAndArrowPreferences1.Dispose()
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
Next
'Change Settings for DatumFeatureSymbols
For Each tempDatumFeatureSymbol As Annotations.DraftingDatum In workPart.Gdts
Dim symbolPreferences2 As Annotations.SymbolPreferences
symbolPreferences2 = tempDatumFeatureSymbol.GetSymbolPreferences()
Dim lineAndArrowPreferences1 As Annotations.LineAndArrowPreferences
lineAndArrowPreferences1 = tempDatumFeatureSymbol.GetLineAndArrowPreferences()
Dim letteringPreferences1 As Annotations.LetteringPreferences
letteringPreferences1 = tempDatumFeatureSymbol.GetLetteringPreferences()
Dim generalText2 As Annotations.Lettering
generalText2.Size = 3.5
generalText2.CharacterSpaceFactor = 0.0
generalText2.AspectRatio = 0.8
generalText2.LineSpaceFactor = 1.0
generalText2.Cfw.Color = 37
generalText2.Cfw.Font = fntArial
generalText2.Cfw.Width = Annotations.LineWidth.Thin
generalText2.Italic = False
letteringPreferences1.SetGeneralText(generalText2)
tempDatumFeatureSymbol.SetLetteringPreferences(letteringPreferences1)
letteringPreferences1.Dispose()
lineAndArrowPreferences1.Dispose()
symbolPreferences2.SetWeldSpaceFactor(2.0)
symbolPreferences2.SetWeldSymbolSizeFactor(1.0)
Dim weldSymbolCfw1 As Annotations.LineCfw = New Annotations.LineCfw(37, DisplayableObject.ObjectFont.Solid, Annotations.LineWidth.Thin)
symbolPreferences2.SetWeldSymbolCfw(weldSymbolCfw1)
Dim surfaceFinishCfw1 As Annotations.LineCfw = New Annotations.LineCfw(37, DisplayableObject.ObjectFont.Solid, Annotations.LineWidth.Thin)
symbolPreferences2.SetSurfaceFinishCfw(surfaceFinishCfw1)
symbolPreferences2.DraftingSurfaceFinishStandard = Annotations.SurfaceFinishStandard.Iso2002
symbolPreferences2.WeldSymbolStandard = Annotations.WeldStandard.Iso
tempDatumFeatureSymbol.SetSymbolPreferences(symbolPreferences2)
symbolPreferences2.Dispose()
tempDatumFeatureSymbol.LeaderOrientation = Annotations.LeaderOrientation.FromLeft
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId1)
Next
End Sub
End Module
--------------------------------------------------------------------------------------------
Each section here is working ok, but if I have a drawing that includes both feature control frames and Datum Feature Symbols, it does not work. I think this is because of these lines:
For Each tempFcF As Annotations.DraftingFcf In workPart.Gdts
and this one:
For Each tempDatumFeatureSymbol As Annotations.DraftingDatum In workPart.Gdts
I want to run through all Feature control frames and change the settings for each one. So here I am saving a draftingFcf from workpart.Gdts to tempFcf. Since workpart.Gdts returns both DraftingFcf and
DraftingDatums when the script finds a DraftingDatum and tries to save it as a draftingFcf it crashes.
So my question is how can I search for just DraftingFcfs or just DraftingDatums in my workpart? Or maybe there is a better way of doing this?
Thanks in advance!
Stian L. Amstrup