Quantcast
Channel: NX Journaling - Journaling / NXOpen API
Viewing all 783 articles
Browse latest View live

Get Length of Stiffener System in Basic Design application

$
0
0

Hello Everyone,

I'm new here and with NX journal, but had already read too much topics from this site(thanks!) and from Siemens documentation.

Now I'm trying to extract a material list from structure application, specific for Basic Design. Where the profiles(stiffener system) are created as Solid bodies inside the primary structure part.

Considering that I'm trying to get the length of this solid body, but don't now how.

The system create a spline that have the length information but I don't know how the spline and the solid body are connected internaly. Because I'm looping by all solid bodies, they have all attributes I need, and now is just missing the length.

I tryed looping by the edges of the solid body but there is too much edges and I don't know which one have the correct length.

Some images from the elements:
image1: https://drive.google.com/file/d/1VSN9avxKH9dUuN9WRCP5NDygQO6F1dL2/view?u...

image2: https://drive.google.com/file/d/1uvGxOTlqO-VP2iMGYMBtGRowrY5167ei/view?u...

Any idea how can I get the length or find the spline asociated with the solid body?

Thank you


Journal to Create components(layer wise) from Assembly bodies after reading File names from an Excel

$
0
0

We normally Model/mock stuff as bodies at assembly level and then move those bodies into components. I tried automating this , so that the new part names are read from an excel file, and the solid bodies(which are segregated by layer no's) are then Cut and pasted into the new part. Everything works fine, the only problem I am facing now is that the new parts also have duplicate dumb solids of the bodies which I previously copied into them. I am manually deleting those.
Can someone Please look at the below code and let me know where the problem is?
PS: This is my first Post here :)

' NX 11.0.2.7' Journal created by lavjit jain on Thu Aug 13 21:44:23 2020 India Standard Time'Option Strict Off
Imports System
Imports System.Collections.GenericImports NXOpen
Imports NXOpen.UF 
Module CreateDetails
 
   	Dim theSession As Session = Session.GetSession()Dim theUfSession As UFSession = UFSession.GetUFSession() 
    	Dim theUI As UI = UI.GetUI()Dim lw As ListingWindow = theSession.ListingWindow 
	Structure GMDetail
		Dim PartName    AsStringDim LayerNo   AsIntegerDim DBPartName    AsStringEndStructure 
	Private excelFileName AsString="C:\Users\lavjitja\Desktop\macros\test template\Create Details.xlsx"Dim displayPart As NXOpen.Part= theSession.Parts.DisplayDim workPart As NXOpen.Part= theSession.Parts.Work 
    Sub Main() 
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Add component") 
        'save the assembly locationDim parentFolder AsString= IO.Path.GetDirectoryName(theSession.Parts.Display.FullPath) 
	' Try to access ExcelDim objExcel =CreateObject("Excel.Application") 
 
	' Open Excel workbook (filename, confirm conversion = false, open read-only = true)Dim objWorkbook = objExcel.Workbooks.Open(excelFileName, false, true) 
         Dim row AsInteger
         row =2' we skip the first row, as we assume this contains the column headings. 
         Dim rowData As GMDetail
 
         ' Loop over all data in the spreadsheet 
           Do' Read data from spreadsheet
                rowData.LayerNo= objExcel.Cells(row, 2).Value
                rowData.PartName= objExcel.Cells(row, 3).Value
			rowData.DBPartName= objExcel.Cells(row, 4).Value
                theSession.ListingWindow().WriteLine("Object: "+ rowData.PartName+" read data.") 
 
                ' If the objType is not empty, call function to assign the attributes for the objectIfNotString.IsNullOrWhiteSpace(rowData.LayerNo) 
				'code for getting all objects on a particular layerDim objs()As NXObject = displayPart.Layers.GetAllObjectsOnLayer(rowData.LayerNo) 
				'create new components   
				CreateNewComponent(objs, IO.Path.Combine(parentFolder, rowData.PartName&".f01.0010.prt"), rowData.LayerNo, rowData.DBPartName) 
 
                EndIf 
                row = row +1' next row until we find an empty one 
            Loop Until String.IsNullOrWhiteSpace(rowData.LayerNo) 
            ' Close Excel
            objExcel.Quit 
 
 
 
        'save the display part (the assembly)Dim theSaveStatus As PartSaveStatus
        theSaveStatus = theSession.Parts.Display.Save(BasePart.SaveComponents.True, False) 
 
	EndSub 
 
	'code for adding component: 
	Sub CreateNewComponent(ByVal objects()As NXObject, ByVal fileName AsString, ByVal layernum AsString,ByVal DBPart AsString) 
        	Dim markId1 As NXOpen.Session.UndoMarkId=Nothing
		markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Add Component") 
		Dim basePart1 As NXOpen.BasePart=NothingDim partLoadStatus1 As NXOpen.PartLoadStatus=Nothing
		basePart1 = theSession.Parts.OpenBase("C:\Users\lavjitja\Desktop\macros\test template\mbXXXXXXl.f01.0010_Part.prt", partLoadStatus1) 
		partLoadStatus1.Dispose() 
		Dim basePoint1 As NXOpen.Point3d=New NXOpen.Point3d(0.0, 0.0, 0.0)Dim orientation1 As NXOpen.Matrix3x3=Nothing
	orientation1.Xx=1.0
	orientation1.Xy=0.0
	orientation1.Xz=0.0
	orientation1.Yx=0.0
	orientation1.Yy=1.0
	orientation1.Yz=0.0
	orientation1.Zx=0.0
	orientation1.Zy=0.0
	orientation1.Zz=1.0Dim partLoadStatus2 As NXOpen.PartLoadStatus=NothingDim component1 As NXOpen.Assemblies.Component=Nothing
	component1 = workPart.ComponentAssembly.AddComponent("C:\Users\lavjitja\Desktop\macros\test template\mbXXXXXXl.f01.0010_Part.prt", "PART", "MBXXXXXXL.F01.0010_PART", basePoint1, orientation1, layernum , partLoadStatus2, True) 
	partLoadStatus2.Dispose() 
	Dim partLoadStatus3 As NXOpen.PartLoadStatus=Nothing
	theSession.Parts.SetWorkComponent(component1, NXOpen.PartCollection.RefsetOption.Current, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus3) 
	workPart = theSession.Parts.Work' mbXXXXXXl.f01.0010_Part
	partLoadStatus3.Dispose()
	WorkPart.SetAttribute("DB_PART_NAME", DBPart )
	WorkPart.SetAttribute("DB_PART_DESC", DBPart ) 
 
' ----------------------------------------------'   Menu: File->Save As...' ----------------------------------------------Dim partSaveStatus1 As NXOpen.PartSaveStatus=Nothing
	partSaveStatus1 = workPart.SaveAs(filename) 
	partSaveStatus1.Dispose() 
 
	Dim nullNXOpen_Assemblies_Component As NXOpen.Assemblies.Component=Nothing 
	Dim partLoadStatus4 As NXOpen.PartLoadStatus=Nothing
	theSession.Parts.SetWorkComponent(nullNXOpen_Assemblies_Component, NXOpen.PartCollection.RefsetOption.Current, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus4) 
	workPart = theSession.Parts.Work' TEST DATA
	partLoadStatus4.Dispose()' ----------------------------------------------'   Menu: Edit->Copy' ----------------------------------------------
workPart.PmiManager.RestoreUnpastedObjects() 
Dim markId8 As NXOpen.Session.UndoMarkId=Nothing
markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Copy") 
Dim copyCutBuilder1 As NXOpen.Gateway.CopyCutBuilder=Nothing
copyCutBuilder1 = workPart.ClipboardOperationsManager.CreateCopyCutBuilder() 
copyCutBuilder1.CanCopyAsSketch=False 
copyCutBuilder1.IsCut=True 
copyCutBuilder1.ToClipboard=True 
copyCutBuilder1.DestinationFilename=Nothing 
 
copyCutBuilder1.SetObjects(objects) 
 
 
Dim nXObject1 As NXOpen.NXObject=Nothing
nXObject1 = copyCutBuilder1.Commit() 
copyCutBuilder1.Destroy() 
theSession.DeleteUndoMark(markId8, Nothing) 
Dim markId9 As NXOpen.Session.UndoMarkId=Nothing
markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Make Work Part") 
Dim partLoadStatus5 As NXOpen.PartLoadStatus=Nothing
theSession.Parts.SetWorkComponent(component1, NXOpen.PartCollection.RefsetOption.Current, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus5) 
workPart = theSession.Parts.Work' asdasd
partLoadStatus5.Dispose()
theSession.SetUndoMarkName(markId9, "Make Work Part") 
' ----------------------------------------------'   Menu: Edit->Paste' ----------------------------------------------Dim markId10 As NXOpen.Session.UndoMarkId=Nothing
markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Paste") 
Dim pasteBuilder1 As NXOpen.Gateway.PasteBuilder=Nothing
pasteBuilder1 = workPart.ClipboardOperationsManager.CreatePasteBuilder() 
Dim nXObject2 As NXOpen.NXObject=Nothing
nXObject2 = pasteBuilder1.Commit() 
pasteBuilder1.Destroy() 
Dim markId11 As NXOpen.Session.UndoMarkId=Nothing
markId11 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Make Work Part") 
Dim partLoadStatus6 As NXOpen.PartLoadStatus=Nothing
theSession.Parts.SetWorkComponent(nullNXOpen_Assemblies_Component, NXOpen.PartCollection.RefsetOption.Current, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus6) 
workPart = theSession.Parts.Work' TEST DATA
partLoadStatus6.Dispose()
theSession.SetUndoMarkName(markId11, "Make Work Part") 
 
 
 
 
    	EndSub 
EndModule

Point transformation from Local to Global WCS

$
0
0

Hi,

I'm trying to transform a point3d information from a JT component inside JT assembly.
The point is based on the WCS of that particular component.
I need to transform this point to the WCS of the whole assembly.

The code showed in the links below are not working.
1. http://nxjournaling.com/content/moving-component-csys-csys
2. https://www.nxjournaling.com/content/create-points-faces-and-get-coordin...

I'm using C# for performing this operation.
Kindly help me on this.

Thanks

Rotate elements in pattern

$
0
0

Hi together,

my journal contains a pattern option.
I would like to rotate every pattern element beginning from the first one by 30°. Is there any possibility to do it?

Best regards,

Benedict

Save points of pattern feature

$
0
0

Hi together,

i have written a NX Journal, which creates a honeycomb pattern.

Now i want to save all the craeted corner points of each polygon in a .txt file, or .xls or whatever.

Is there any possibility to do this?

Best regards,
Benedict

Export .prt to hard drive

$
0
0

Hello

Is it possible to export a .prt to the hard drive, even though NX is connected to TeamCenter? I'm using VBA and it doesn't have to work with assemblys.

Kind Regards

NXHelper library for NXOpen

$
0
0

When i started programming application extensions with NX Open, i quickly noticed that many simple methods were missing. i have developed and published a small library that provides a few of these functions. the developers among you are welcome to submit new methods or improvements via pull request. I haven't been working with the NX Open API that long myself, but I hope that I can make work easier for a few people with the provided classes

https://github.com/AlexMitDemBart/NXHelper

a few example functions of the library:

publicstaticbool RefsetExist(Part workpart, string refSetName){
   List<ReferenceSet> refsetList = workpart.GetAllReferenceSets().Where(x => x.Name.Equals(refSetName)).ToList();bool refsetExist = refsetList.Count>0?true:false;return refsetExist;} 
publicstatic ReferenceSet GetReferenceSet(Part workpart, string refSetName){
   List<ReferenceSet> refsetList = workpart.GetAllReferenceSets().Where(x => x.Name.Equals(refSetName)).ToList();return refsetList.First();} 
publicstatic List<Body> GetSolidBodiesFromRefset(Part workpart, ReferenceSet refset){
   List<Body> solidBodies =new List<Body>();
   List<NXObject> objList = refset.AskAllDirectMembers().ToList();foreach(NXObject obj in objList){
      Body body = TryConvertNxObjectToBody(obj);if(body !=null&& body.IsSolidBody){
             solidBodies.Add(body);}} 
    return solidBodies;}

Import Assembly into Teamcenter

$
0
0

I keep getting an error on the line that 'ufs.Clone.PerformClone(Nothing)'
I don't Know How to Fix. plz.Help~~

Option Strict Off
Imports System
Imports System.IOImports System.CollectionsImports System.Windows.FormsImports NXOpen
Imports NXOpenUI
Imports NXOpen.UFImports NXOpen.UIImports NXOpen.UtilitiesImports NXOpen.PDM 
Module Import_Assy
    Dim theSession As Session = Session.GetSession()Dim theUI As UI = UI.GetUI()Dim ufs As UFSession = UFSession.GetUFSession()Dim pathsave AsString="" 
    Sub Main() 
        TryDim FolderBrowserDialog AsNew FolderBrowserDialog
            With FolderBrowserDialog
                .RootFolder= Environment.SpecialFolder.Desktop.SelectedPath="D:\NX_Data\import\".Description="Select the directory to Import"If.ShowDialog= DialogResult.OKThen
                    pathsave =.SelectedPathElse'user pressed "cancel", exit the journalExitSubEndIfEndWith 
        Catch ex As NXException
            ExitSub 
        EndTry 
        ufs.Clone.Terminate()
        ufs.Clone.Initialise(UFClone.OperationClass.ImportOperation)
        ufs.Clone.SetFamilyTreatment(UFClone.FamilyTreatment.StripFamilyStatus)
        ufs.Clone.SetDefDirectory(pathsave)
        ufs.Clone.SetDefAction(UFClone.Action.Overwrite)'ufs.Clone.SetDefAction(UFClone.Action.UseExisting)
        ufs.Clone.SetLogfile(pathsave +"\"+"Import.log")
        ufs.Clone.SetDefAssocFileCopy(False)
        ufs.Clone.SetDefFolder("tceadm:Test")
        ufs.Clone.SetDefOwner("migration")
        ufs.Clone.SetDefGroup("dba")
        ufs.Clone.SetDefNaming(UFClone.NamingTechnique.Autotranslate)
        ufs.Clone.SetDefPdmName("${DB_PART_NAME}")
        ufs.Clone.SetDefPdmDesc("${DB_PART_NAME}")Dim naming_failures As UFClone.NamingFailures 
        Dim DirInfo AsNew IO.DirectoryInfo(pathsave)Dim FileList As IO.FileInfo()= DirInfo.GetFiles("*.prt")Dim foundfile As IO.FileInfo 
 
        ' get the files in the directory'================================ForEach foundfile In FileList
            ufs.Clone.AddAssembly(pathsave +"\"+ foundfile.Name, Nothing)
            ufs.Clone.AddPart(pathsave +"\"+ foundfile.Name)
            ufs.Clone.SetAssocFileCopy(foundfile.Name, False)Next'================================= 
        ufs.Clone.InitNamingFailures(naming_failures)
        ufs.Clone.SetDryrun(False)
        ufs.Clone.GenerateReport()
        ufs.Clone.PerformClone(Nothing)
        ufs.Clone.Terminate() 
    EndSub 
    Sub Echo(ByVal output AsString)
        theSession.ListingWindow.Open()
        theSession.ListingWindow.WriteLine(output)
        theSession.LogFile.WriteLine(output)EndSub 
    PublicFunction GetUnloadOption(ByVal dummy AsString)AsInteger 
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately 
    EndFunction 
EndModule

CustomFeature

$
0
0

Hi there - I am playing with the (newish) CustomFeature capabilities and have successfully created one which works. Has anybody managed to create instances of their custom features from code?? The method SetConstructionFeatures can only be accessed through a dialog box event - and because I am not running interactively I have no dialog.

The parts created by my code do contain my code called instances but the contain no geometry until you edit and ok/apply on that feature.

Any ideas of how I can make this work??

Thanks,

Paul

Get text of notes defined by Attributes or Exressions

$
0
0

Hello

I have created textboxes in windows form to collect notes from drawing sheets which are defined by unique attributes or expressions. Now, I want to get the values of these notes in textboxes created in windows form so that I can make changes to these notes once we get those in respective textboxes.

For example: I have created new note as "NOTE-1" on sheet-1 of drawing and Set Attribute to this note as "AttrNote-1" through note property option.

The Attribute "AttrNote-1" will be fixed all the time since it is an attribute defined by user and Value of this attribute is "NOTE-1" which can be changed as per convenience. NoW, I want to search value of note (i.e "NOTE-1") by its attribute (i.e AttrNote-1) and Need to get the value of note in textbox created in windows form for "Note-1" So, I should be able to first read the value of note in textbox and make changes to it if needed.

Same case is for expression as well. For expressions, Name of expression will be treated as Attribute (i.e exprNote_1) and its value in the formula bar will be treated as Value of Note (i.e NOTE-1)

Could someone provide journal for this requirements.

Thanks in advance.

Determine if component is being shown?

$
0
0

So I use a method that I have seen many places before to cycle through all children for the displayed part. I am outputting certain properties from these children and saving to a CSV file.

Before I run my journal file, I apply a variant condition to only allow certain children. The problem is that when I run the journal, it shows ALL children, including those that were suppressed by the variant condition. I do not want this. I only want it to process those that obey the variant condition, which were already filtered.

Is there a property I can use to identify if the component is allowed by the variant?

My code:

'Journal to recursively walk through the assembly structure
' will run on assemblies or piece parts
' will step through all components of the displayed part
'NX 7.5, native
'NXJournaling.com February 24, 2012

Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies

Module NXJournal

Public theSession As Session = Session.GetSession()
Public ufs As UFSession = UFSession.GetUFSession()
Public lw As ListingWindow = theSession.ListingWindow
Public myWriter as IO.StreamWriter
Public outputFile As String
Public outputString as String

Sub Main()
Dim workPart As Part = theSession.Parts.Work
Dim dispPart As Part = theSession.Parts.Display

Dim myDocs As String
myDocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
outputFile = IO.Path.Combine(myDocs, "Length_of_Line.csv")

outputString = ""
lw.Open
'open only for testing

Try
Dim c As ComponentAssembly = dispPart.ComponentAssembly
'to process the work part rather than the display part,
' comment the previous line and uncomment the following line
'Dim c As ComponentAssembly = workPart.ComponentAssembly
if not IsNothing(c.RootComponent) then
'*** insert code to process 'root component' (assembly file)
Dim sub_comp As Component
sub_comp = c.RootComponent
'*** end of code to process root component
'If sub_comp.Prototype.OwningPart.IsFullyLoaded Then
If sub_comp.IsSuppressed Then
'Do nothing if supressed
Else
'If sub_comp.Prototype.OwningPart.IsFullyLoaded then
'If c.IsOccurrence = true Then
lw.writeline(c.OwningPart.ComponentAssembly.ActiveArrangement.Name)
ReportComponentChildren(c.RootComponent, 0)
'End if
End If
else
'*** insert code to process piece part

end if
Catch e As Exception
theSession.ListingWindow.WriteLine("Failed: "& e.ToString)
End Try
lw.Close

Using myWriter As New IO.StreamWriter(outputFile, False)
myWriter.Writeline("File,Mass,Volume,Material,Material Number, Length of Line")
myWriter.write(outputString)
End Using

End Sub

'**********************************************************
Sub reportComponentChildren( ByVal comp As Component, _
ByVal indent As Integer)

For Each child As Component In comp.GetChildren()
'*** insert code to process component or subassembly

'*** end of code to process component or subassembly

'**try to get attributes of each component too

dim material as string = ""
dim mass as string = ""
dim volume as string = ""

dim material_number as string

try
material = child.getStringAttribute("P_MAT")
catch
material = ""
end try

try
mass = child.getStringAttribute("P_MASS")
catch
mass = ""
end try

try
volume = child.getStringAttribute("P_VOLUME")
catch
volume = ""
end try

material = Replace(material,",","")

Dim pos As Integer
Dim pos2 As Integer

pos = InStr(material, "998")
pos2 = InStr(material, "GMW15200")

if pos <> 0 or pos2 <> 0 then

if Len(material) >= 8 and pos <> 0 then
material_number = material.Substring(pos-1,7)
else
if Len(material) >= 8 and pos2 <> 0 then
material_number = material.Substring(pos2-1,8)
else
material_number = ""
end if
end if

outputString = outputString & child.DisplayName() & ","& mass & ","& volume & ","& material & ","& material_number

'open part as displayed part then grab length of line
Dim basePart11 As NXOpen.BasePart = Nothing
Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
Dim totalCurveLength As Double

totalCurveLength = 0

try

basePart11 = theSession.Parts.OpenBaseDisplay("@DB/"& child.DisplayName() , partLoadStatus1)

'shouldn't need to change actual displayed layer, since curve measurement is filtering by layer already
'Dim stateArray1(1) As NXOpen.Layer.StateInfo
'stateArray1(0) = New NXOpen.Layer.StateInfo(3, NXOpen.Layer.State.WorkLayer)
'stateArray1(1) = New NXOpen.Layer.StateInfo(1, NXOpen.Layer.State.Hidden)
'basePart11.Layers.ChangeStates(stateArray1, False)

totalCurveLength = 0
'iterate through the curve collection, add curve length to the running total
For Each aCurve As Curve In basePart11.Curves
If aCurve.Layer = 3 then
'If aCurve.Visible = true then
totalCurveLength += aCurve.GetLength
end if
Next

'report the component name, part file name, and total curve length

basePart11.Close(BasePart.CloseWholeTree.True, BasePart.CloseModified.CloseModified, Nothing)

catch
end try

lw.WriteLine("Lengh of Line = "& totalCurveLength.ToString)
lw.WriteLine("")

outputString = outputString & ","& totalCurveLength.ToString & Chrw(13)

end if

'**end getting attributes

if child.GetChildren.Length <> 0 then
'*** this is a subassembly, add code specific to subassemblies

'*** end of code to process subassembly
else
'this component has no children (it is a leaf node)
'add any code specific to bottom level components
end if

'*** end of code to process root component
'If sub_comp.Prototype.OwningPart.IsFullyLoaded Then
If child.IsSuppressed Then
'Do nothing if supressed
Else
'If child.Prototype.OwningPart.IsFullyLoaded then
'If child.IsOccurrence = true Then
lw.writeline(child.OwningPart.ComponentAssembly.ActiveArrangement.Name)
reportComponentChildren(child, indent + 1)
'End If
End If

Next
End Sub
'**********************************************************
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function
'**********************************************************

End Module

Error While Looping Over Collection

$
0
0

Hello all!

NX10 - Strange error which only happens on a handful of drawings out of 50+. When looping over a collection in the part object it gets mad about something being changed/committed while looping? I can't figure it out. Any help is greatly appreciated! Cheers.

Error = "NXopen.NXException: Collection does not support modification while iteration in progress..."

Journal to Create components(layer wise) from Assembly bodies after reading File names from an Excel

$
0
0

We normally Model/mock stuff as bodies at assembly level and then move those bodies into components. I tried automating this , so that the new part names are read from an excel file, and the solid bodies(which are segregated by layer no's) are then Cut and pasted into the new part. Everything works fine, the only problem I am facing now is that the new parts also have duplicate dumb solids of the bodies which were cut-pasted into them, I am manually deleting those.
Can someone Please look at the below code and let me know where the problem is?
PS: This is my first Post here :)

' NX 11.0.2.7' Journal created by lavjit jain on Thu Aug 13 21:44:23 2020 India Standard Time'Option Strict Off
Imports System
Imports System.Collections.GenericImports NXOpen
Imports NXOpen.UF 
Module CreateDetails
 
   	Dim theSession As Session = Session.GetSession()Dim theUfSession As UFSession = UFSession.GetUFSession() 
    	Dim theUI As UI = UI.GetUI()Dim lw As ListingWindow = theSession.ListingWindow 
	Structure GMDetail
		Dim PartName    AsStringDim LayerNo   AsIntegerDim DBPartName    AsStringEndStructure 
	Private excelFileName AsString="C:\Users\lavjitja\Desktop\macros\test template\Create Details.xlsx"Dim displayPart As NXOpen.Part= theSession.Parts.DisplayDim workPart As NXOpen.Part= theSession.Parts.Work 
    Sub Main() 
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Add component") 
        'save the assembly locationDim parentFolder AsString= IO.Path.GetDirectoryName(theSession.Parts.Display.FullPath) 
	' Try to access ExcelDim objExcel =CreateObject("Excel.Application") 
 
	' Open Excel workbook (filename, confirm conversion = false, open read-only = true)Dim objWorkbook = objExcel.Workbooks.Open(excelFileName, false, true) 
         Dim row AsInteger
         row =2' we skip the first row, as we assume this contains the column headings. 
         Dim rowData As GMDetail
 
         ' Loop over all data in the spreadsheet 
           Do' Read data from spreadsheet
                rowData.LayerNo= objExcel.Cells(row, 2).Value
                rowData.PartName= objExcel.Cells(row, 3).Value
			rowData.DBPartName= objExcel.Cells(row, 4).Value
                theSession.ListingWindow().WriteLine("Object: "+ rowData.PartName+" read data.") 
 
                ' If the objType is not empty, call function to assign the attributes for the objectIfNotString.IsNullOrWhiteSpace(rowData.LayerNo) 
				'code for getting all objects on a particular layerDim objs()As NXObject = displayPart.Layers.GetAllObjectsOnLayer(rowData.LayerNo) 
				'create new components   
				CreateNewComponent(objs, IO.Path.Combine(parentFolder, rowData.PartName&".f01.0010.prt"), rowData.LayerNo, rowData.DBPartName) 
 
                EndIf 
                row = row +1' next row until we find an empty one 
            Loop Until String.IsNullOrWhiteSpace(rowData.LayerNo) 
            ' Close Excel
            objExcel.Quit 
 
 
 
        'save the display part (the assembly)Dim theSaveStatus As PartSaveStatus
        theSaveStatus = theSession.Parts.Display.Save(BasePart.SaveComponents.True, False) 
 
	EndSub 
 
	'code for adding component: 
	Sub CreateNewComponent(ByVal objects()As NXObject, ByVal fileName AsString, ByVal layernum AsString,ByVal DBPart AsString) 
        	Dim markId1 As NXOpen.Session.UndoMarkId=Nothing
		markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Add Component") 
		Dim basePart1 As NXOpen.BasePart=NothingDim partLoadStatus1 As NXOpen.PartLoadStatus=Nothing
		basePart1 = theSession.Parts.OpenBase("C:\Users\lavjitja\Desktop\macros\test template\mbXXXXXXl.f01.0010_Part.prt", partLoadStatus1) 
		partLoadStatus1.Dispose() 
		Dim basePoint1 As NXOpen.Point3d=New NXOpen.Point3d(0.0, 0.0, 0.0)Dim orientation1 As NXOpen.Matrix3x3=Nothing
	orientation1.Xx=1.0
	orientation1.Xy=0.0
	orientation1.Xz=0.0
	orientation1.Yx=0.0
	orientation1.Yy=1.0
	orientation1.Yz=0.0
	orientation1.Zx=0.0
	orientation1.Zy=0.0
	orientation1.Zz=1.0Dim partLoadStatus2 As NXOpen.PartLoadStatus=NothingDim component1 As NXOpen.Assemblies.Component=Nothing
	component1 = workPart.ComponentAssembly.AddComponent("C:\Users\lavjitja\Desktop\macros\test template\mbXXXXXXl.f01.0010_Part.prt", "PART", "MBXXXXXXL.F01.0010_PART", basePoint1, orientation1, layernum , partLoadStatus2, True) 
	partLoadStatus2.Dispose() 
	Dim partLoadStatus3 As NXOpen.PartLoadStatus=Nothing
	theSession.Parts.SetWorkComponent(component1, NXOpen.PartCollection.RefsetOption.Current, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus3) 
	workPart = theSession.Parts.Work' mbXXXXXXl.f01.0010_Part
	partLoadStatus3.Dispose()
	WorkPart.SetAttribute("DB_PART_NAME", DBPart )
	WorkPart.SetAttribute("DB_PART_DESC", DBPart ) 
 
' ----------------------------------------------'   Menu: File->Save As...' ----------------------------------------------Dim partSaveStatus1 As NXOpen.PartSaveStatus=Nothing
	partSaveStatus1 = workPart.SaveAs(filename) 
	partSaveStatus1.Dispose() 
 
	Dim nullNXOpen_Assemblies_Component As NXOpen.Assemblies.Component=Nothing 
	Dim partLoadStatus4 As NXOpen.PartLoadStatus=Nothing
	theSession.Parts.SetWorkComponent(nullNXOpen_Assemblies_Component, NXOpen.PartCollection.RefsetOption.Current, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus4) 
	workPart = theSession.Parts.Work' TEST DATA
	partLoadStatus4.Dispose()' ----------------------------------------------'   Menu: Edit->Copy' ----------------------------------------------
workPart.PmiManager.RestoreUnpastedObjects() 
Dim markId8 As NXOpen.Session.UndoMarkId=Nothing
markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Copy") 
Dim copyCutBuilder1 As NXOpen.Gateway.CopyCutBuilder=Nothing
copyCutBuilder1 = workPart.ClipboardOperationsManager.CreateCopyCutBuilder() 
copyCutBuilder1.CanCopyAsSketch=False 
copyCutBuilder1.IsCut=True 
copyCutBuilder1.ToClipboard=True 
copyCutBuilder1.DestinationFilename=Nothing 
 
copyCutBuilder1.SetObjects(objects) 
 
 
Dim nXObject1 As NXOpen.NXObject=Nothing
nXObject1 = copyCutBuilder1.Commit() 
copyCutBuilder1.Destroy() 
theSession.DeleteUndoMark(markId8, Nothing) 
Dim markId9 As NXOpen.Session.UndoMarkId=Nothing
markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Make Work Part") 
Dim partLoadStatus5 As NXOpen.PartLoadStatus=Nothing
theSession.Parts.SetWorkComponent(component1, NXOpen.PartCollection.RefsetOption.Current, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus5) 
workPart = theSession.Parts.Work' asdasd
partLoadStatus5.Dispose()
theSession.SetUndoMarkName(markId9, "Make Work Part") 
' ----------------------------------------------'   Menu: Edit->Paste' ----------------------------------------------Dim markId10 As NXOpen.Session.UndoMarkId=Nothing
markId10 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Paste") 
Dim pasteBuilder1 As NXOpen.Gateway.PasteBuilder=Nothing
pasteBuilder1 = workPart.ClipboardOperationsManager.CreatePasteBuilder() 
Dim nXObject2 As NXOpen.NXObject=Nothing
nXObject2 = pasteBuilder1.Commit() 
pasteBuilder1.Destroy() 
Dim markId11 As NXOpen.Session.UndoMarkId=Nothing
markId11 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Make Work Part") 
Dim partLoadStatus6 As NXOpen.PartLoadStatus=Nothing
theSession.Parts.SetWorkComponent(nullNXOpen_Assemblies_Component, NXOpen.PartCollection.RefsetOption.Current, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus6) 
workPart = theSession.Parts.Work' TEST DATA
partLoadStatus6.Dispose()
theSession.SetUndoMarkName(markId11, "Make Work Part") 
 
 
 
 
    	EndSub 
EndModule

.vb or Journal Program

$
0
0

Hi

Looking for a .vb or Journal program or guideline which can automatically plot all dimesions( overall size, hole positions, hole dimensions) for tha part. Yes i know this is much similar to Feature parameters ( but in feature parameter Extrude, Revlove dimensions). Can i anyone help on this topic.

Thanks
Sathish S

Arranging Planes

$
0
0

Hello everybody,

I have a confusion.

I would like to create datum planes, which allows user to get two inputs; distance from reference datum plane & number of planes. For instance, user want to create 5 planes which have 200mm distance between each plane. I have done the distance part, but i cannot find the part of code that change the number of planes.

I use VB for coding.

Can somebody help me with this issue.


Read Model Normal to face orientation

$
0
0

Is there any way to read the X,Y,Z orientation based on a certain normal-to-face (F8) state of a model?

Which would give a result for example: XDirection as (1,0,0) and NormalDirection as (0,0,1)

Currently I am hardcoding the coordinates for XDirection and Normal Direction, but reading these two direction by the currentnormal state would be helpful.

User Instruction without freezing background operation

$
0
0

What is the best way to use message box for instruction only for user to tell what to do without freezing everything else and user can then hit OK to proceed to the next steps?

Blockstyler dialog within Blockstyler dialog?

$
0
0

Hi everyone,

Does anyone know if you can/how to launch a blockstyler UI (for example a search box or a set of buttons) from inside another blockstyler? The second UI would have to be able to return values from itself to the first UI.

Thanks,
Nick

Centre of gravity of a Face

$
0
0

Hello All,

I'm creating a report in the ship structure application, and had dificulty to extract the COG for each face.

I'm using the function ufs.Modl.AskMassProps3d but this function needs a body(solid or sheet body)

Is there another function that ask for a Face rather than a body?

As another option there is any way to generate a "virtual" body from a face, then use the AskMassProps3d ?

Thank you in advance

Problem with VB Debugging

$
0
0

Does anyone know if you can use the Visual Studio Debugger if you don't have an authoring license? (I'm using VS2019 and NX12.0). If I play a journal, and the journal has the line below in it:

"System.Diagnostics.Debugger.Launch()"

I can almost get the debugger to work but I get a exception:

"An unhandled exception of type 'System.ExecutionEngineException' occurred in FrustumNX.dll"

and then NX crashes.

Guess I'm just looking to see if anyone has the VS debugger working without a authoring license.FYI, I have a older computer with NX11 and VS2010 and debugging a journal works (I didn't compile it). Besides the NX and VS versions, the only other difference I can tell is I do have a authoring lic on the older computer.

Thanks

Viewing all 783 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>