Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IFRs on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Journal-wave link all visible bodies from all components 2

Status
Not open for further replies.

kukelyk

Industrial
Mar 21, 2005
315
My manufacturing project workflow starts as the next:
Open the workpiece part; create new parent, link all solid bodies from the part under 'MODEL' reference set.

When I try to record this process, it records like:
Code:
Dim component1 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT model2 1"), Assemblies.Component)
Dim body1 As Body = CType(component1.FindObject("PROTO#.Bodies|BLOCK(1)"), Body)
I know the name of the component, which contains the needed body. I know, that the bodies are visible, because i check the models when i open it.
Could someone please help me?

----
kukelyk
 
Replies continue below

Recommended for you

hi

I have a journal to setup EDM electrode´s

As it is now - following functions.

1.Your workpiece part must be displayed part.
2.Staying in modelling
3.Run journal ...
4.New part is created , workpiece part is now component name.
5.Name of new part is as component name+"ELEKTRODE_NR--1.
6.New part is located in same dir as workpiece part ´
7.If you run it again with workpiece part as displayed part, new name will be incremented 1. (component name+"ELEKTRODE_NR--2), (component name+"ELEKTRODE_NR--3) and so on...
8.A linked body will be created on layer 12 - color is change to 31 ,cyan.
9.Component is blanked .


-----------------

I think it easy can be can be changed to meet your requirements.

lklo

 
 http://files.engineering.com/getfile.aspx?folder=b394866e-3ad9-4e4e-931d-305809252b64&file=new_parent_elektrode_auto_name_+_LinkBody.vb
Thanks a lot!
First of all I need this for EDM electrodes' manufacturing too. [medal]

----
kukelyk
 
there is some error at the download. could You please upload it in a zip file?

----
kukelyk
 
hi

I will upload a zip file tonight..

lklo
 
Many thanks, work as expected on NX8, but with errors on NX 7.5

----
kukelyk
 
I keep running into a

Code:
NXOpen.NXException: The selected template doesn't exist
  at NXOpen.Builder.Commit()
  at NXJournal.Main() in C:\Users\me\AppData\Local\Temp\NXJournals3568\journal.vb:Line 60

which refers to this line

Code:
        nXObject1 = fileNew1.Commit()
 
hi -

I dont have nx7.5 ,
but I suggest you to simply make a simple journal record,
containing a sequence where you make a procedure with "Create New Parent".

after that - see the records specialy the > fileNew1.***** lines < , maybee you see an difference.

maybee >fileNew1.UseBlankTemplate=False< should bee True.??

ps: of course the > fileNew1.NewFileName = FinalNewPartName < , should bee as it is.

lklo
 
Here is what I have, I kept recieving the same error when I created a simple journal for creating a new component and creating a new parent as well.
Therefore, I commented out the
'nXObject1 = fileNew1.Commit()
line and now I am having issues with the component command line. It is saying there is an issue with an object I called for this command.
"incorrect object for this operation"

Code:
Option Strict Off  
Imports System  
Imports System.IO  
Imports NXOpen  
Imports NXOpen.UF 

Module NXJournal
Sub Main

Dim theUI As UI = UI.GetUI()
Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim partname As String  
Dim workpart As Part = theSession.Parts.work
Dim disp_partname As String
Dim displayPart As Part = theSession.Parts.Display
Dim comp As String
Dim Revcomp As String
Dim insert as String
       
        partname = path.GetFileNameWithoutExtension(workPart.FullPath)
        comp = partname
        insert = "__Rev"
        Revcomp = comp .insert(5, insert)
        'Msgbox(comp & chr(13) & Revcomp)

            Dim partLoadStatus2 As PartLoadStatus
            Dim status1 As PartCollection.SdpsStatus
            status1 = theSession.Parts.SetDisplay(displaypart, False, True, partLoadStatus2)
            workPart = theSession.Parts.Work
            displayPart = theSession.Parts.Display
            partLoadStatus2.Dispose()
            'Msgbox(partname)
           
'To find folder name and such
Dim folderName As String = "C:"  
 'assign output folder to workpart folder
        folderName = Path.GetDirectoryName(workPart.FullPath)

           'Msgbox(foldername)

 Dim fileNew1 As FileNew
        fileNew1 = theSession.Parts.FileNew()
        fileNew1.Application = FileNewApplication.Assemblies
        fileNew1.Units = Part.Units.Inches
        fileNew1.TemplateFileName = "Modeling\english-model-template_c.prt"
        fileNew1.NewFileName = foldername & "\" & Revcomp & ".prt"
        'fileNew1.Application = FileNewApplication.Modeling
        fileNew1.MasterFileName = ""
        fileNew1.UseBlankTemplate = False
        fileNew1.MakeDisplayedPart = False
        Dim nXObject1 As NXObject

       '
        'nXObject1 = fileNew1.Commit()
       '

        workPart = theSession.Parts.Work
        displayPart = theSession.Parts.Display
        fileNew1.Destroy()

        Dim sPartFullPath As String = theSession.Parts.Display.FullPath
        'Dim part1 As Part = CType(theSession.Parts.FindObject(Revcomp), Part)
        Dim basePoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
        Dim orientation1 As Matrix3x3
        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.0
        Dim partLoadStatus1 As PartLoadStatus
        Dim component1 As Assemblies.Component
        component1 = workPart.ComponentAssembly.AddMasterPartComponent(displayPart , "True" , Revcomp, basePoint1, orientation1, 50, partLoadStatus1)

'I wanted the component to be placed directely under the display part so I changed that, as well as part name and layer.

End Sub
End Module
 
Here is a simple journal which addresses the later question re creating the component.

This journal only works once since it creates the component part both as a loaded part and a saved part. It is simple to add code to check for existing loaded part and/or existing saved part which if they exist can be used instead of creating new part.

Also note the line

Dim fullpathname1 As String = "C:\ugs\nx75\UGII\html_files\model_template_metric.prt"

which needs to be changed to suit your templates
Code:
Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies

Module NXJournal
    Sub Main()

        Dim theUI As UI = UI.GetUI()
        Dim theSession As Session = Session.GetSession()
        Dim lw As ListingWindow = theSession.ListingWindow()
        Dim ufs As UFSession = UFSession.GetUFSession()
        Dim partname As String
        Dim workpart As Part = theSession.Parts.Work
        Dim disp_partname As String = Nothing
        Dim displayPart As Part = theSession.Parts.Display
        Dim comp As String
        Dim Revcomp As String
        Dim insert As String
        Dim partLoadStatus2 As NXOpen.PartLoadStatus = Nothing

        partname = Path.GetFileNameWithoutExtension(workpart.FullPath)
        comp = partname
        insert = "__Rev"
        Revcomp = partname & insert

        'To find folder name and such
        Dim folderName As String = Path.GetDirectoryName(workpart.FullPath)
        Dim fullpathname1 As String = "C:\ugs\nx75\UGII\html_files\model_template_metric.prt"
        Dim fullpathname2 As String = folderName & "\" & Revcomp & ".prt"
        File.Copy(fullpathname1, fullpathname2)

        Dim basePart1 As BasePart = theSession.Parts.OpenBase(fullpathname2, partLoadStatus2)
        Dim part2 As Part = CType(basePart1, Part)
        Dim basePoint1 As Point3d = New Point3d(0.0, 0.0, 0.0)
        Dim orientation1 As Matrix3x3
        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.0
        Dim component1 As Component = workpart.ComponentAssembly.AddComponent(part2, "Model", Revcomp, _
                                                         basePoint1, orientation1, 50, partLoadStatus2)

    End Sub
    Public Function GetUnloadOption(ByVal arg As String) As Integer
        Return CType(Session.LibraryUnloadOption.Immediately, Integer)
    End Function
End Module


Frank Swinkels
 
Thank you Frank for that! I appreciate it, that was what I was looking for. The only problem I am running into is that the component is coming in as a read only file and I anything I do to it, will not be saved by a save or save all command. Any ideas on how to fix this?
 
I adapted the above code to my situtation, but the problem is the part is a Read-only Part. Any changes I make I will not be able to save under that name.
I can import the part and it will replace the new part I created but then that just creates a bigger problem.
If anyone can help me with this, I would really appreciate it. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor