It is currently Tue May 21, 2013 10:07 am

All times are UTC





Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: VB script
PostPosted: Tue Jun 21, 2011 7:40 pm 
Offline
MCAD Lurker

Joined: 11 Nov 2010
Posts: 3
Country: United States
State: NewYork
CAD System: Inventor
Hi,
Anybody want a take a stab at writing a script to pull some dimensions ( in English)and put them in a table or CSV?

I'm trying to get Inspection Dimensions from Inventor 2011 into a table.
the method , I believe, is:

GetInspectionDimensionData


TIA

DJMike :)


Share on FacebookShare on TwitterShare on DiggShare on DeliciousShare on TumblrShare on Google+
Top
 Profile  
 
 Post subject: Re: VB script
PostPosted: Tue Jun 21, 2011 8:35 pm 
Offline
MCAD Addict
User avatar

Joined: 22 Mar 2004
Posts: 530
Country: United States
State: Pennsylvania
CAD System: Inventor
Are you the Mike from the similar post? :) I can give you an example later tonight.

Best Regards,

_________________
Robert A. Williams
http://www.leacar.com
"Gentlemen...you can't fight here. This is the War Room!"


Top
 Profile  
 
 Post subject: Re: VB script
PostPosted: Wed Jun 22, 2011 10:13 am 
Offline
MCAD Lurker

Joined: 11 Nov 2010
Posts: 3
Country: United States
State: NewYork
CAD System: Inventor
No I'm my own Mike but The other Mike sits one office down and the two of us are combining resourses to try and achieve some code to help our company.
Thanks for the offer and YES we both will look at any code you can offer as an example.

Regards,
DJMike


Top
 Profile  
 
 Post subject: Re: VB script
PostPosted: Wed Jun 22, 2011 12:34 pm 
Offline
MCAD Addict
User avatar

Joined: 22 Mar 2004
Posts: 530
Country: United States
State: Pennsylvania
CAD System: Inventor
Here is a sample of how to get the information that you want. I think you need at least Inventor 2011 (can't remember if INV 2010 API had the "IsInspectionDimension" Property....I know INV 2009 did not) This example was designed to work in the Inventor VBA environment. You'd have to modify for Excel.

Code:
Private Sub DisplayInspectionDims()

Dim invDDOC As Inventor.DrawingDocument
Dim invSHEETS As Inventor.Sheets
Dim invActSHT As Inventor.Sheet
Dim invDDIMS As Inventor.DrawingDimensions
Dim invActDIM As Inventor.DrawingDimension
Dim invDDText As Inventor.DimensionText
Dim invUOM As Inventor.UnitsOfMeasure

Dim strSheetName As String

    'no error checking...
    'active document must be a drawing document...
    Set invDDOC = ThisApplication.ActiveDocument
    Set invUOM = ThisApplication.UnitsOfMeasure
    Set invSHEETS = invDDOC.Sheets
    For Each invActSHT In invSHEETS
        strSheetName = invActSHT.Name
        Set invDDIMS = invActSHT.DrawingDimensions
        For Each invActDIM In invDDIMS
            If invActDIM.IsInspectionDimension Then
                Set invDDText = invActDIM.Text
                Debug.Print "**************"
                Debug.Print "Sheet: " & strSheetName
                Debug.Print "Display Text: " & invDDText.Text
                If invActDIM.ModelValueOverridden Then
                    Debug.Print "Dimension Value IS OVERRIDDEN"
                End If
                'internal length values are in cm...
                Debug.Print "Model Value (inch): " & _
                    CStr(invUOM.ConvertUnits(invActDIM.ModelValue, "cm", "in"))
                Debug.Print "Model Value (mm): " & _
                    CStr(invUOM.ConvertUnits(invActDIM.ModelValue, "cm", "mm"))
            End If
        Next
    Next
End Sub


Best Regards,

_________________
Robert A. Williams
http://www.leacar.com
"Gentlemen...you can't fight here. This is the War Room!"


Top
 Profile  
 
 Post subject: Re: VB script
PostPosted: Wed Jun 22, 2011 12:45 pm 
Offline
MCAD Lurker

Joined: 21 May 2010
Posts: 16
Country: United States
State: NewYork
CAD System: Inventor
Thanks !


Top
 Profile  
 
 Post subject: Re: VB script
PostPosted: Wed Jun 22, 2011 3:08 pm 
Offline
MCAD Lurker

Joined: 11 Nov 2010
Posts: 3
Country: United States
State: NewYork
CAD System: Inventor
Robert,
That was a huge help.
I have no pride at this point and will ask if you know also how to pull the Inspection Dimension Label "Letter" info and print both the dimension & label to either Excel or CVS.
Micbar and I haven't written code in nearly five years and are very rusty.
We want to generate a table with the Label letter and dimension for checking on our plant floor.
Typically only about 8 or 9 dimensions on a sheet are critical and need to be logged.
We have our old school books out and are playing around with code but keep hitting brick walls.
Use it or lose it right?

Either way, thank you very much for the code you have already supplied.

Regards,

DJMike & Micbar


Top
 Profile  
 
 Post subject: Re: VB script
PostPosted: Wed Jun 22, 2011 4:53 pm 
Offline
MCAD Addict
User avatar

Joined: 22 Mar 2004
Posts: 530
Country: United States
State: Pennsylvania
CAD System: Inventor
DJMike and Micbar:

I am attaching a macro that is meant to be run from inside Excel. Open up a blank Worksheet in Excel. Enter the VBA environment, Add an empty Module and paste this code into it. You'll also have to add a reference to "Autodesk Inventor Object Library" in the References dialog.

Make sure you have your drawing open and active in Inventor before you run this in Excel.

You can modify it to better suit your needs. Hopefully this gives you everything you need.

Best Regards,
Robert W.

Code:
Option Explicit

Public Sub GetInspectionDimDataFromInventor()

Dim invDDOC As Inventor.DrawingDocument
Dim invSHEETS As Inventor.Sheets
Dim invActSHT As Inventor.Sheet
Dim invDDIMS As Inventor.DrawingDimensions
Dim invActDIM As Inventor.DrawingDimension
Dim invDDText As Inventor.DimensionText
Dim invUOM As Inventor.UnitsOfMeasure
Dim invAPP As Inventor.Application
Dim invIDShapeEnum As Inventor.InspectionDimensionShapeEnum

Dim exActWS As Excel.Worksheet
Dim exCells As Excel.Range

Dim strSheetName As String
Dim strIDLabel As String
Dim strIDRate As String
Dim intIndex As Integer

    'no error checking...
    'active document must be a drawing document...
    'set a reference to the 'Autodesk Inventor Object Library'
   
    Set invAPP = GetObject(, "Inventor.Application")
    Set invDDOC = invAPP.ActiveDocument
    Set invUOM = invAPP.UnitsOfMeasure
    Set invSHEETS = invDDOC.Sheets
    Set exActWS = ActiveWorkbook.ActiveSheet
    Set exCells = exActWS.Cells
    exCells(1, 2).Value = "Label"
    exCells(1, 3).Value = "Dimension Text"
    exCells(1, 4).Value = "Exact Distance"
    exCells(1, 5).Value = "Overridden"
    intIndex = 2
    For Each invActSHT In invSHEETS
        strSheetName = invActSHT.Name
        Set invDDIMS = invActSHT.DrawingDimensions
        For Each invActDIM In invDDIMS
            If invActDIM.IsInspectionDimension Then
                Set invDDText = invActDIM.Text
                invActDIM.GetInspectionDimensionData invIDShapeEnum, strIDLabel, strIDRate
                exCells(intIndex, 2).Value = strIDLabel
                exCells(intIndex, 3).Value = invDDText.Text
                exCells(intIndex, 4).Value = CStr(invUOM.ConvertUnits(invActDIM.ModelValue, "cm", "in"))
                If invActDIM.ModelValueOverridden Then
                    exCells(intIndex, 5).Value = "YES"
                Else
                    exCells(intIndex, 5).Value = "NO"
                End If
                intIndex = intIndex + 1
            End If
        Next
    Next

End Sub

_________________
Robert A. Williams
http://www.leacar.com
"Gentlemen...you can't fight here. This is the War Room!"


Top
 Profile  
 
 Post subject: Re: VB script
PostPosted: Wed Jun 22, 2011 7:08 pm 
Offline
MCAD Lurker

Joined: 21 May 2010
Posts: 16
Country: United States
State: NewYork
CAD System: Inventor
Robert,

That helped alot, thanks so much. I was able to tweak the cloumns the data is populated in so that some math can be done on the numbers and it can be easily imported / copy pasted back into a "table" in Inventor to appear on the face of the drawing, any idea of a eaiser way to do this? I cant think of one.

The end goal is to create a table on the face of the drawing with
Letter ..... Min Value .... Actual Value (filled in in the shop) and Max value. Right now we are using excel to calculate the min and max based on a column for tolerance (normally we use a standard tolerance, once in a while there will be a dim that is held tighter / looser)

- Micbar and DJMike


Top
 Profile  
 
 Post subject: Re: VB script
PostPosted: Wed Jun 22, 2011 7:25 pm 
Offline
MCAD Addict
User avatar

Joined: 22 Mar 2004
Posts: 530
Country: United States
State: Pennsylvania
CAD System: Inventor
Glad it worked for you!

The easiest way to display Excel tabular data in Inventor is to use the Table feature in the Inventor drawing environment. You can link your Excel to the table with no cut/paste.

Robert W.

_________________
Robert A. Williams
http://www.leacar.com
"Gentlemen...you can't fight here. This is the War Room!"


Top
 Profile  
 
 Post subject: Re: VB script
PostPosted: Wed Sep 14, 2011 2:33 pm 
Offline
MCAD Regular
User avatar

Joined: 26 Nov 2007
Posts: 212
Country: United States
State: Illinois
CAD System: Inventor
Robert,

I apologize for picking this thread up late... I have actually been working on a similar project to the two Mike's request. I had developed a very similar code as to your first example. My question would be the sorting. If I am using alpha characters for my strIDLabel, can I script a function to place the values in ascending order? i.e. Inspection Label A in Cell A1, Inspection Label B in Cell A2. I also notice your code places the data into cell B1, is there a reason for this? Thanks in advance!!!

_________________
Todd P.


Top
 Profile  
 
 Post subject: Re: VB script
PostPosted: Wed Sep 14, 2011 6:06 pm 
Offline
MCAD Addict
User avatar

Joined: 22 Mar 2004
Posts: 530
Country: United States
State: Pennsylvania
CAD System: Inventor
Hi Todd:

You could use the value of strIDLabel to determine which cell to put its value (assuming you have a label = "A" thru "Z")

If strIDLabel = "A" -> Cell A1 ="B" -> Cell A2 etc...
Code:
'....snippet
Dim intCOL as Integer

intCOL = Asc (UCase (strIDLabel)) - 64
exCells(1, intCOL).Value = invDDText.Text

And no, the Row/Column assignments can be anything you want.

Best Regards,

_________________
Robert A. Williams
http://www.leacar.com
"Gentlemen...you can't fight here. This is the War Room!"


Top
 Profile  
 
 Post subject: Re: VB script
PostPosted: Wed Sep 14, 2011 6:21 pm 
Offline
MCAD Regular
User avatar

Joined: 26 Nov 2007
Posts: 212
Country: United States
State: Illinois
CAD System: Inventor
Robert,

Thanks for the quick response! I understand what your snippet is doing, would it work in your code sample provided above and if so where would it need to reside? Thanks again! :D

_________________
Todd P.


Top
 Profile  
 
 Post subject: Re: VB script
PostPosted: Wed Sep 14, 2011 6:45 pm 
Offline
MCAD Addict
User avatar

Joined: 22 Mar 2004
Posts: 530
Country: United States
State: Pennsylvania
CAD System: Inventor
Todd:
You're welcome! Here is the entire routine with the modification. I corrected from the snippet when I realized it is the ROW you wanted to index.

Best Regards,
Robert W.
Code:
Option Explicit

Public Sub GetInspectionDimDataFromInventor()

Dim invDDOC As Inventor.DrawingDocument
Dim invSHEETS As Inventor.Sheets
Dim invActSHT As Inventor.Sheet
Dim invDDIMS As Inventor.DrawingDimensions
Dim invActDIM As Inventor.DrawingDimension
Dim invDDText As Inventor.DimensionText
Dim invUOM As Inventor.UnitsOfMeasure
Dim invAPP As Inventor.Application
Dim invIDShapeEnum As Inventor.InspectionDimensionShapeEnum

Dim exActWS As Excel.Worksheet
Dim exCells As Excel.Range

Dim strSheetName As String
Dim strIDLabel As String
Dim strIDRate As String

DIM intROW As Integer

    'no error checking...
    'active document must be a drawing document...
    'set a reference to the 'Autodesk Inventor Object Library'
   
    Set invAPP = GetObject(, "Inventor.Application")
    Set invDDOC = invAPP.ActiveDocument
    Set invUOM = invAPP.UnitsOfMeasure
    Set invSHEETS = invDDOC.Sheets
    Set exActWS = ActiveWorkbook.ActiveSheet
    Set exCells = exActWS.Cells
    exCells(1, 1).Value = "Label"
    exCells(1, 2).Value = "Dimension Text"
    exCells(1, 3).Value = "Exact Distance"
    exCells(1, 4).Value = "Overridden"
    For Each invActSHT In invSHEETS
        strSheetName = invActSHT.Name
        Set invDDIMS = invActSHT.DrawingDimensions
        For Each invActDIM In invDDIMS
            If invActDIM.IsInspectionDimension Then
                Set invDDText = invActDIM.Text
                invActDIM.GetInspectionDimensionData invIDShapeEnum, strIDLabel, strIDRate
                intROW = Asc (UCase (strIDLabel)) - 63
                exCells(intROW, 1).Value = strIDLabel
                exCells(intROW, 2).Value = invDDText.Text
                exCells(intROW, 3).Value = CStr(invUOM.ConvertUnits(invActDIM.ModelValue, "cm", "in"))
                If invActDIM.ModelValueOverridden Then
                    exCells(intROW, 4).Value = "YES"
                Else
                    exCells(intROW, 4).Value = "NO"
                End If
            End If
        Next
    Next

End Sub

_________________
Robert A. Williams
http://www.leacar.com
"Gentlemen...you can't fight here. This is the War Room!"


Top
 Profile  
 
 Post subject: Re: VB script
PostPosted: Wed Sep 14, 2011 7:13 pm 
Offline
MCAD Regular
User avatar

Joined: 26 Nov 2007
Posts: 212
Country: United States
State: Illinois
CAD System: Inventor
Robert,

AWESOME!!! I owe you! One last question, I have a dimension where I am using the linear dimension option, and after I run this macro, excel does not seem to be able to parse the string for the dia. symbol (


You do not have the required permissions to view the files attached to this post. You must LOGIN or REGISTER to view these files.

_________________
Todd P.


Top
 Profile  
 
 Post subject: Re: VB script
PostPosted: Wed Sep 14, 2011 7:47 pm 
Offline
MCAD Regular
User avatar

Joined: 26 Nov 2007
Posts: 212
Country: United States
State: Illinois
CAD System: Inventor
Robert,

Could I also access iProperties within this macro. For instance say I had a cell (i.e. A15) within this excel document that I wanted to populate with the part number [nvPartNumberProperty] or a custom iProperty, is this possible? As always thank again!

_________________
Todd P.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
POWERED_BY