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!

Drawing with master model and journal to replace component

Status
Not open for further replies.

PSI-CAD

Computer
Feb 13, 2009
997
Hi,

I have 50 models of different size and I have made the drawing for the first size

I use replace component then save as the drawing for the second size

I developped the given journal for 4 sizes (replace component, update body measurement, start drafting, update, save as)

How to create an array that contain the listing of file in current directory, and use it to create a loop ?

Thanks in advance


Regards
Didier Psaltopoulos
 
Replies continue below

Recommended for you

I found the following lines to read the listing:


Dim fileReader As String
fileReader = My.Computer.FileSystem.ReadAllText("F:\listing.txt")

Then the following to check the result

MsgBox(fileReader)

But How to use the result in a loop ?

Thanks in advance


Regards
Didier Psaltopoulos
 
Didier,

To one line of the file at at time, use that line as input until the end of the file...

Code:
Imports System
Imports NXopen
[highlight #4E9A06]Imports System.IO[/highlight]
[highlight #4E9A06]Imports System.Text[/highlight]

... In the "Sub Main"

Code:
        Dim inputfile As String = "F:\listing.txt" 
        Dim theline As String = Nothing
        Try 

            Dim sr As StreamReader = New StreamReader(inputfile)

            Do While sr.Peek() >= 0
                theline = sr.ReadLine()

                ' Use theline to open the part or create the new string(s) for the save-as file name(s) etc.
                ' The original code goes here but references the variables that you define based on theline vs 
                 'the strings "F:\B5223020FEM20.prt" etc.

            Loop
            sr.Close()
        Catch e As Exception
            theSession.ListingWindow.WriteLine("The process failed: " & e.ToString)
        End Try
...

HTH,
Joe
 
Hi Joe,

Thanks a lot, I was able to start my vb step by step.

my initial assy is:

B5223020FEM20_dwg1
|
|---B5223020FEM20

and listing.txt contains

B5223006FEM06
B5223006FEM08

I would like to replace B5223020FEM20 by B5223006FEM06 then save the assy B5223006FEM06_dwg1.prt

then replace B5223006FEM06 by B5223008FEM08 then save the assy B5223008FEM08_dwg1.prt

Step 1:
I have created save_as_ok.vb and it works well

Step 2:
I have tried to add lines between ' START REPLACE COMPONENT and ' END REPLACE COMPONENT (replace_and_save_as.vb)

But it does not work

Maybe something is wrong in the following line:

component1 = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT" + theline + "1"), Assemblies.Component)



Thanks in advance for your help.



Regards
Didier Psaltopoulos
 
Didier,

The order of events in the pseudo-code from the original post'"(replace component, update body measurement, start drafting, update, save as) describes a sensible workflow.

There are two variants.

1) Repeated open the original assembly (B5223020FEM20_dwg1) and perform that sequence of operations (so that the name of the component to replace is predictable (B5223020FEM20)).

Or
2) Open the original assembly and repeatedly perform the sequence of operations (replace component, update body measurement, start drafting, update, save as) on the currently opened assembly that resulted from the most recent save-as.

If that is the desired approach then you have to keep changing the name of the component to "find" for the replacement based on the replacement that had been done on the previous iteration of replace..save-as. In other words, the data from the readline for the previous save-as needs to be used for find component for the component to be replaced and the current readline needs to beused for the component to replace (and the basis for the name to save-as).

The current code seems to be an incomplete mixture of both approaches.

Hopefully this will help you to choose what to do next.

Regards,

Joe

 
Hi Joe,

I am looking for the solution 2.

I have a problem with the following line:

component1 = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT" + theline + "1"), Assemblies.Component)

What's wrong ?

TIA


Regards
Didier Psaltopoulos
 
Didier,

I think...

The value of theline is the file name and the save-as to that name has not happened yet so the "find" can't find that component.

Regards,

Joe
 
Didier,

After the existing line (13)
Code:
Dim theSession As Session = Session.GetSession()
add the following two lines
Code:
Dim LW As ListingWindow = theSession.ListingWindow
LW.Open()

Then use the following to display the value value (line 83).
Code:
LW.WriteLine("The current value of theline = " & theline)

HTH
Joe
 
Thanks Joe,

I was able to write the content of theline at different steps.

Now, I have the following error

The current value of theline = B5223006FEM06
The process failed: System.NullReferenceException: Object reference not set to an instance of an object.
at NXJournal.Main() in C:\Users\Didier\AppData\Local\Temp\NXJournals3316\journal.vb:line 62

I have a question: what's the limit to develop simple program without NXOpen licence ?

TIA


Regards
Didier Psaltopoulos
 
Didier,

My understanding is that without a license for NXopen or Snap the following can be used:

[ul square]
[li]- Mini-SNAP (to evaluate the SNAP concepts and the IDE (e.g. intellisense) benefits)[/li]
[ul]
[li] This is limited to the sub set of SNAP functions that mini-SNAP presents.[/li]
[/ul]
[/ul]
[ul square]
[li]- Journals Via the NX Journal Editor[/li]

[ul][li] Multiple .Net languages are supported. (E.g. Java, C#, C++, VB)[/li]
[li] This can be the results of “record journal” so that example code can be created without having to “write” the code.[/li]
[li] All of the source code must reside in a single file.[/li]
[li] This can be explicitly authored journaling calls[/li]
[li] This can include the use of Microsoft Winforms for creation of custom user interfaces.[/li]
[li] The NXopen functions that have wrappers can also be invoked from the journals.[/li]
[li] Access to the functions is not determined by any programming author license. It is controlled by the[/li]
[li] traditional NX feature licensing.[/li]
[/ul]
[/ul]

For example, if one has only a modeling license the journal can call any modeling function (e.g. extrude)
but not a free-form function (e.g. global shaping) which would require a free form license.
(It is not possible to use NX automation to get access to functions that are not available in the
current license file interactively in NX)​

HTH,

Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor