Monday, September 29, 2014

Drawing View Scale Part II

In my last post, I discussed one solution to get a drawing view scale.  That solution found the drawing view with the lowest numerical value as part of view name (VIEW1, VIEW5, etc.) and used it's scale as an iProperty of the drawing.


Another solution that my client wanted was to present all the view names and allow the user to select which view he/she wanted to represent the scale in the title block.


Like the first solution, we cycled through each sheet on the drawing and looked at the view name.  If the view name begins with "VIEW" then it was used to build a one dimensional array.  We also concatenated the view scale with the view name to satisfy the needs of seeing both the view name and the view scale.

'    Cycle thru each sheet.  Build array of View Name and View Scale.
     For Each oSheet In oSheets
         oViews = oSheet.DrawingViews
         For Each oView In oViews
             oViewName = oView.Name
             If Left(oViewName,4) = "VIEW" Then
                 oScale = oView.Scale
                 oConc = oViewName & ": @ " & oScale
                 oViewList.Add(oConc)
             End If
         Next
     Next

We then sorted the array and set a MultiValue list using that array.

'    Sort array
     oViewList.Sort

'    Set Multi-Value List from array
     MultiValue.List("ViewList") = oViewList

Next we presented an input box to the user using the MultiValue list.

'    Present Input Box for user selection
     selected = InputListBox("Select a view from the list", _
     MultiValue.List("ViewList"), oViewList.item(0), Title := "Views", _
     ListName := "View Name @ Scale")

Next we extracted the view name and view scale from the user selection.

'    Extract View Name and View Scale from user selection    
     delimpos = InStr(selected, "@")
     oSelectedView = Left(selected,delimpos - 1)
     oSelectedScale = Right(selected,Len(selected)-delimpos)

Finally, the view scale was pushed to a custom iProperty that was displayed in the drawing title block.

'    Set custom iProperty based on user selection
     iProperties.Value("Custom", "Scale") = RoundToFraction(oSelectedScale, 1/8, _
     RoundingMethod.Round) & ":1"

The full code is listed here:

'    Setting Variables
     Dim oDrawDoc As DrawingDocument = ThisDrawing.Document
     Dim oSheet As Sheet
     Dim oSheets As Sheets
     oSheets = oDrawDoc.Sheets
     Dim oView As DrawingView
     Dim oViews As DrawingViews
    
     Dim oScale As Double
     Dim oViewName As String
     Dim oConc as String
     Dim oSelectedView As String
     Dim oSelectedScale As String
     Dim oViewList As New ArrayList
    
'    Cycle thru each sheet.  Build array of View Name and View Scale.
     For Each oSheet In oSheets
         oViews = oSheet.DrawingViews
         For Each oView In oViews
             oViewName = oView.Name
             If Left(oViewName,4) = "VIEW" Then
                 oScale = oView.Scale
                 oConc = oViewName & ": @ " & oScale
                 oViewList.Add(oConc)
             End If
         Next
     Next

'    Sort array
     oViewList.Sort

'    Set Multi-Value List from array
     MultiValue.List("ViewList") = oViewList
    
'    Present Input Box for user selection
     selected = InputListBox("Select a view from the list", _
     MultiValue.List("ViewList"), oViewList.item(0), Title := "Views", _
     ListName := "View Name @ Scale")
    
'    Extract View Name and View Scale from user selection    
     delimpos = InStr(selected, "@")
     oSelectedView = Left(selected,delimpos - 1)
     oSelectedScale = Right(selected,Len(selected)-delimpos)

'    Set custom iProperty based on user selection
     iProperties.Value("Custom", "Scale") = RoundToFraction(oSelectedScale, 1/8, _
     RoundingMethod.Round) & ":1"
    
'    Update
     iLogicVb.UpdateWhenDone = True

PS - Sorry about the formatting.  I can't seem to get those extra spaces out of the sections where I've broken up the code.

Please leave a comment and let me know what you think.

Randy

"Opportunity is missed by most people because it is dressed in overalls and looks like work." - Thomas Edison

Tuesday, September 23, 2014

Drawing View Scale Part I

Even in today's CAD world, we often include and display the drawing scale in the title block.  In the past, this was more of a requirement than it is today.  Today someone on the manufacturing floor can just as easily (and more accurately) pull up the CAD model on their terminal and take measurements. There are many students in my training classes that don't even know what item is shown in the image below.

Engineer's Scale
It is a typical practice for Inventor users to display the scale of the first view created in the drawing title block.

I recently ran into a situation where the client wanted two methods to pull a drawing scale to include in the title block:

  1. Find the view name with the lowest numerical value and use its scale in the title block
  2. Present the user with all drawing views, and their scales, on a drawing and allow the user to select which view he/she wanted to represent the scale in the title block

I'll discuss the first solution in this blog post.  The solution included just a few steps.

We cycled through each sheet on the drawing and looked at each view name.  If the view name begins with "VIEW" then it was used to build an one dimensional array.  This step ensured we didn't pull views such as section or detail views.

'    Cycle thru each sheet.  Build array of View Name and View Scale.    
     For Each oSheet In oSheets
     oViews = oSheet.DrawingViews
         For Each oView In oViews    
            oViewName = oView.Name
            If Left(oViewName,4) = "VIEW" Then
                temp = Right(oViewName,1)
                oViewList.Add(temp)
            End If
         Next
     Next

We then sorted the array and pulled the view scale of the first index of the array.

'    Sort array
     oViewList.Sort
    
'    Get scale of lowest View
     oSelectedScale = ActiveSheet.View("VIEW" & oViewList(0)).Scale

The view scale was pushed to a custom iProperty that was displayed in the drawing title block.

'    Set custom iProperty based on user selection
     iProperties.Value("Custom", "Scale") = RoundToFraction(oSelectedScale, 1/8, _
     RoundingMethod.Round) & ":1"

The full code is listed here:

'    Setting Variables
     Dim oDrawDoc As DrawingDocument = ThisDrawing.Document
     Dim oSheet As Sheet
     Dim oSheets As Sheets
     oSheets = oDrawDoc.Sheets
     Dim oView As DrawingView
     Dim oViews As DrawingViews
    
     Dim oScale As Double
     Dim oViewName As String
     Dim oViewList As New ArrayList
    
'    Cycle thru each sheet.  Build array of View Name and View Scale.    
     For Each oSheet In oSheets
     oViews = oSheet.DrawingViews
         For Each oView In oViews    
            oViewName = oView.Name
            If Left(oViewName,4) = "VIEW" Then
                temp = Right(oViewName,1)
                oViewList.Add(temp)
            End If
         Next
     Next
    
'    Sort array
     oViewList.Sort
    
'    Get scale of lowest View
     oSelectedScale = ActiveSheet.View("VIEW" & oViewList(0)).Scale

'    Set custom iProperty based on user selection
     iProperties.Value("Custom", "Scale") = RoundToFraction(oSelectedScale, 1/8, _
     RoundingMethod.Round) & ":1"
    
'    Update
     iLogicVb.UpdateWhenDone = True

Next post I'll discuss the second option where we displayed the view names and scales and allowed the user to select which scale to use in the title block.

As always, leave a comment and let us know how this has helped you.

Randy

"The difference between try and triumph is a little umph." - Unknown

Friday, September 12, 2014

Searching Excel with iLogic II: Header Rows

A few blogs back, my partner in crime Carl Smith posted about searching Excel with iLogic as a means of gathering data for ever changing projects.  This has come in handy multiple times for me.


I recently had a case where a client had a very nice looking Excel file with data at the top.  This forced the column headers I was searching for down a few rows.  An example is shown to the right.

By default, the GoExcel.FindRow likes the Column that is searching for to be in Row 1 of the worksheet.

This can be changed by using GoExcel.TitleRow.  This will allow you to tell iLogic what row to start looking for column names.

Before your GoExcel.FindRow command, add:

GoExcel.TitleRow = X

Replace the X with the row your Column headings are located in.

Here is what the code section would look like:

GoExcel.TitleRow = 8
i = GoExcel.FindRow("SalesOrders.xlsx", "Header", "Part Number", "=", PartNumber)

Description = GoExcel.CurrentRowValue("Description")
Length = GoExcel.CurrentRowValue("Length")

Randy


"I have not failed. I've just found 10,000 ways that won't work.~Thomas A. Edison