Drawing with master model and journal to replace component
Drawing with master model and journal to replace component
(OP)
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
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
http://www.psi-cad.com





RE: Drawing with master model and journal to replace component
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
http://www.psi-cad.com
RE: Drawing with master model and journal to replace component
To one line of the file at at time, use that line as input until the end of the file...
CODE --> VB
... In the "Sub Main"
CODE --> VB
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 TryHTH,
Joe
RE: Drawing with master model and journal to replace component
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
http://www.psi-cad.com
RE: Drawing with master model and journal to replace component
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
RE: Drawing with master model and journal to replace component
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
http://www.psi-cad.com
RE: Drawing with master model and journal to replace component
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
RE: Drawing with master model and journal to replace component
How to display a value to check it ?
Regards
Didier Psaltopoulos
http://www.psi-cad.com
RE: Drawing with master model and journal to replace component
After the existing line (13)
CODE --> VB
CODE --> VB
Then use the following to display the value value (line 83).
CODE --> VB
LW.WriteLine("The current value of theline = " & theline)HTH
Joe
RE: Drawing with master model and journal to replace component
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
http://www.psi-cad.com
RE: Drawing with master model and journal to replace component
My understanding is that without a license for NXopen or Snap the following can be used:
but not a free-form function (e.g. global shaping) which would require a free form license.
current license file interactively in NX)
HTH,
Joe
RE: Drawing with master model and journal to replace component
Thanks for this clarification
Regards
Didier Psaltopoulos
http://www.psi-cad.com