-
May 3rd, 2016, 03:17 PM
#1
Thread Starter
New Member
(Hopefully) simple user input question
Hello all,
Apologizes if this is the wrong category. I am not well-versed in Visual Basic.
My company uses a Visual Basic file to export drawings from NX Unigraphics to PDFs. IT works well, but doesn't quite do what we need. I've been tweaking the code to match our needs a little better.
Currently, we have drawings with multiple sheets which are all exported by the tool, and i'm trying to add a tool that lets the user select which sheets are exported. The sheets are not named consistently, so i'm finding it difficult to find a method to present consistent options to the user and get consistent answers.
My best solution so far has been to have the user input the sheets they wanted printed by using an InputBox, and then searching their String of input info to see what matches the actual sheet name. It works okay when the sheets are named in numerical order and the user inputs numbers. But occasionally the sheets are labeled things like 'drawing' or 'BOM' which throws everything off, since the user will usually input numbers regardless of the sheet name. Overall this is a god-awful solution and was wondering if anyone could suggest another tool or method that i could look into.
Ideally i'd like to have a popup box with check boxes for each sheet, but i haven't been able to find what i input into the code to get something like that. Any help would be greatly appreciated.
Thanks
-d
-
May 3rd, 2016, 08:24 PM
#2
Re: (Hopefully) simple user input question
How exactly are you accessing the sheets at the moment when exporting all of them? Presumably with a loop of some sort. Is it a For or For Each loop? If it's a For loop, what are you indexing and what do you get from the list by indexing? If it's a For Each loop, what are you looping through and what type is each item?
-
May 4th, 2016, 07:15 AM
#3
Thread Starter
New Member
Re: (Hopefully) simple user input question
Originally Posted by jmcilhinney
How exactly are you accessing the sheets at the moment when exporting all of them?
I am struggling to figure this out. I don't understand how this script interacts with the NX program.
Originally Posted by jmcilhinney
Presumably with a loop of some sort. Is it a For or For Each loop?
This is what the original code is:
Dim dwgs As Drawings.DrawingSheetCollection
dwgs = workPart.DrawingSheets
Dim sheet As Drawings.DrawingSheet
Dim shts As New ArrayList()
For Each sheet In dwgs
shts.Add(sheet.Name)
Next
shts.Sort()
Dim sht As String
For Each sht in shts
For Each sheet in dwgs
If sheet.name = sht Then
[Code for special cases]
[sub to export]
Originally Posted by jmcilhinney
If it's a For Each loop, what are you looping through and what type is each item?
It looks like it's looping through strings in an arraylist (sht in shts) and then inside that it's looping through DrawingSheets in DrawingSheetsCollectino (which i don't understand at all).
I realize i'm probably not knowledgeable enough to ask the right questions, do you have some resources you could point me towards that could read over and ask some better educated questions?
Thanks for the help
-
May 4th, 2016, 08:36 AM
#4
Re: (Hopefully) simple user input question
It's looping through a Drawings.DrawingSheetCollection and each item is apparently a Drawings.DrawingSheet, which apparently has a Name property. You should be able to get all the names like this:
vb.net Code:
Dim sheetNames = dwgs.Select(Function(ds) ds.Name).ToArray()
That will give you a String array containing all the names. You could then load that into a ListBox or CheckedListBox to let the user select the sheets they want. You can then get those sheets by index from the collection.
-
May 4th, 2016, 08:42 AM
#5
Thread Starter
New Member
Re: (Hopefully) simple user input question
Excellent, that sounds like what i'm looking for. I'll play around with that.
Thank you for the quick solution!
-
May 4th, 2016, 09:02 AM
#6
Thread Starter
New Member
Re: (Hopefully) simple user input question
Ah, that was short-lived. Started to experiment with it and received the error
'Select' is not a member of 'NXOpen.Drawings.DrawingSheetCollection'.
What does this mean?
-
May 4th, 2016, 09:23 AM
#7
Re: (Hopefully) simple user input question
Originally Posted by dblazevich
Ah, that was short-lived. Started to experiment with it and received the error
'Select' is not a member of 'NXOpen.Drawings.DrawingSheetCollection'.
What does this mean?
That means that it implements the IEnumerable interface, which is what allows a list to be enumerated and therefore used with a For Each loop, but not the generic IEnumerable(Of T) interface, which is required for use with LINQ methods like Select. You can get an IEnumerable(Of T) from an IEnumerable using the Cast(Of T) method, i.e.
vb.net Code:
Dim sheetNames = dwgs.Select(Function(ds) ds.Name).ToArray()
becomes:
vb.net Code:
Dim sheetNames = dwgs.Cast(Of Drawings.DrawingSheet)().Select(Function(ds) ds.Name).ToArray()
That is basically the LINQ equivalent of the difference between:and:
vb.net Code:
For Each ds As Drawings.DrawingSheet In dwgs
-
May 5th, 2016, 09:08 AM
#8
Thread Starter
New Member
Re: (Hopefully) simple user input question
Okay, thanks for the response. I need to do some more research and try a few things before i can ask follow up questions. I appreciate the help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|