Results 1 to 8 of 8

Thread: (Hopefully) simple user input question

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2016
    Posts
    5

    (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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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?

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2016
    Posts
    5

    Re: (Hopefully) simple user input question

    Quote Originally Posted by jmcilhinney View Post
    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.

    Quote Originally Posted by jmcilhinney View Post
    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]



    Quote Originally Posted by jmcilhinney View Post
    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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:
    1. 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.

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2016
    Posts
    5

    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!

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2016
    Posts
    5

    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?

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: (Hopefully) simple user input question

    Quote Originally Posted by dblazevich View Post
    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:
    1. Dim sheetNames = dwgs.Select(Function(ds) ds.Name).ToArray()
    becomes:
    vb.net Code:
    1. Dim sheetNames = dwgs.Cast(Of Drawings.DrawingSheet)().Select(Function(ds) ds.Name).ToArray()
    That is basically the LINQ equivalent of the difference between:
    vb.net Code:
    1. For Each ds In dwgs
    and:
    vb.net Code:
    1. For Each ds As Drawings.DrawingSheet In dwgs

  8. #8

    Thread Starter
    New Member
    Join Date
    May 2016
    Posts
    5

    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
  •  



Click Here to Expand Forum to Full Width