- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Multiple classes, object references & Shared subs
I'm having a bit of difficulty with some slightly more elaborate classes that I'm working with. To date I've only done a simple one with 3 or 4 values that I passed directly into the class and that was it.
My first class in this code, however, is supposed to be passed a component occurrence. From there it does a look up inside of the function new and gets a variety of parameters and writes them into the various class parameters for ease of access. One of the things its supposed to do is create an array of a secondary class that contains a lot of geometric information involved in the component. That part of the program also needs to do an excel lookup for various information relevant to that geometric information.
Unfortunately I keep getting "Reference to a non-shared member requires an object reference." It does these for all the parameters and the excel lookup. I fixed the parameters by using the component occurrence to reference the component occurrences parameters directly rather than using the assembly parameter function that inventor specifies. However, I see no other way than the FindRow statement in order to do my lookup in excel (excluding the possibility of creating an instance of excel, silently opening the referenced workbook, and doing it manually, something I'm not willing to do quite yet)
I've tried making it shared thus far, but Shared does not apparently allow for public statement and will not allow the passing of parameters into the function, so I'm kinda stuck? Any ideas would be most appreciated.
Thank you,
Thomas Long
Public Class Base
Public BeamList() As Beam
Public oLength As Double
Public oWidth As Double
Public oHeight As Double
Public oName As String
Public oSplits(3) As Boolean
Public oPart As ComponentOccurrence
Public oSectionNumber As Integer
Public Sub New(oPart As ComponentOccurrence)
oDoc = oPart.Definition.Document
MyClass.oLength = oDoc.ComponentDefinition.Parameters.Item("SectionLength").Value
MyClass.oWidth = oDoc.ComponentDefinition.Parameters.Item("SectionWidth").Value
MyClass.oHeight = oDoc.ComponentDefinition.Parameters.Item("GirderHeight").Value
MyClass.oName = oPart.Name
MyClass.oPart = oPart
'MyClass.oSectionNumber = Split(iProperties.Value("Custom", "ETO Item"), "H00")(UBound(Split(iProperties.Value("Custom", "ETO Item"))))
For Each oVal in MyClass.oSplits
oVal = False
Next
If oDoc.ComponentDefinition.Parameters.Item("LengthwiseSplits").Value = "Side A" Or oDoc.ComponentDefinition.Parameters.Item("LengthwiseSplits").Value = "Side A & C" Then MyClass.oSplits(0) = True
If oDoc.ComponentDefinition.Parameters.Item("WidthwiseSplits").Value = "Side B" Or oDoc.ComponentDefinition.Parameters.Item("WidthwiseSplits").Value = "Side B & D" Then MyClass.oSplits(1) = True
If oDoc.ComponentDefinition.Parameters.Item("LengthwiseSplits").Value = "Side C" Or oDoc.ComponentDefinition.Parameters.Item("LengthwiseSplits").Value = "Side A & C" Then MyClass.oSplits(2) = True
If oDoc.ComponentDefinition.Parameters.Item("WidthwiseSplits").Value = "Side D" Or oDoc.ComponentDefinition.Parameters.Item("WidthwiseSplits").Value = "Side B & D" Then MyClass.oSplits(3) = True
ReDim MyClass.BeamList(oDoc.ComponentDefinition.Parameters.Item("Beams").Value-1)
For i = 0 To UBound(MyClass.BeamList)
MyClass.BeamList(i) = New Beam(oDoc.ComponentDefinition.Parameters.Item("Beam_" & i+1).Value, oDoc.ComponentDefinition.Parameters.Item("Location_" & i+1).Value, oDoc.ComponentDefinition.Parameters.Item("Facing_" & i+1).Value)
Next
End Sub
End Class
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'Defines an instance of a beam
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Public Class Beam
Public oSize As String
Public oLocation As Double
Public oFacing As String
Public oFlangeWidth As Double
Public oMidPoint As Double
Public Sub New(oSize As String, oLocation As Double, oFacing As String)
MyClass.oSize = oSize
MyClass.oLocation = oLocation
MyClass.oFacing = oFacing
GoExcel.FindRow("N:\Mechpart\TLONG\Reference Materials\Information\BEAM INFORMATION.xlsx", "Channels", "Beam Size", "=", oSize)
MyClass.oFlangeWidth = GoExcel.CurrentRowValue("FlangeWidth")
If oFacing = "Right"
MyClass.oMidPoint = oLocation + .5*GoExcel.CurrentRowValue("FlangeWidth")
ElseIf oFacing = "Left"
MyClass.oMidPoint = oLocation - .5*GoExcel.CurrentRowValue("FlangeWidth")
End If
End Sub
End Class
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I do not use Inventor, and only wandered into this forum out of curiosity.
It looks like the compiling error "Reference to a non-shared member requires an object reference." is due to the class GoExcel. You did not show its code, but I can guess the method "FindRow()" and "CurrentRowValue()" are both not declared as Shared (static, in C#). As from the code logic, as I can see, they should not be static/Shared anyway, because the GoExcel class needs to hold data read from Excel sheet file. Thus, you need to instantiate an GoExcel object before calling its method.. That is, you need (in the class Beam's constructor):
Dim excel As New GoExcel()
excel.FindRow(".....")
However, in this approach, each time a Beam object is created, you need to open Excel sheet file, find data and then create Beam Class. if you have many beams to create, it would not be very efficient.
The better approach is to read all data at once and use Factory pattern to create beams based the data at once.
Hope this helps a bit.
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So generally inventor has built in functions for it's own programming language, "Ilogic" and the statements Findrow and current row values are properties of the built in GoExcel functionality.
As for factory patterns, I'm sorry I don't know what that is lol. I guess I could declare that it open the data link once before it starts parsing info to the various instances of beams and then just tell it to close when it's done.
Apologies, I'm still not the best at programming.