Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AddVbFile problem

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
marcin_bargiel
286 Views, 3 Replies

AddVbFile problem

Some simplified rule :

header

AddVbFile "common_subs.vb"

 

Sub Main
ADD_PART(SOMETHING)
End Sub 

 

in file common_subs.vb i've got many functions and rules, all work great expect that one :

 

simplified external rule :

 

header :

Imports Inventor

 

Class ThisRule
	Sub ADD_PART(ByVal PART As Double)
			Components.Add(CHILD_NAME, newAssembly, position := Nothing, grounded := False, visible := True, appearance := Nothing)
			Constraints.AddUcsToUcs("Flush_" & CHILD_NAME, CHILD_NAME, "UCS", PARENT_NAME, UCS_PARENT)
			iProperties.Value(CHILD_NAME, "Project", "Part Number") = Part_Number
	End Sub
End Class

 

 I've got those errors and I have no idea what to do with it. When Subroutine ADD_PART was previously in the original rule (not external connected by AddVbFile), it worked fine. :


Error on Line 281 : 'Constraints' is not declared. It may be inaccessible due to its protection level.
Error on Line 287 : 'iProperties' is not declared. It may be inaccessible due to its protection level.

 

Vote for REPLACE VARIES !
REPLACE VARIES
3 REPLIES 3
Message 2 of 4

please upload your complete code so that we have all variable complete!

Regards,

Arthur Knoors

Autodesk Affiliations:

Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!


! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Message 3 of 4

This happens because external VB file MUST contain only pure VB.NET code. You can't use iLogic shortcuts directly (like "iProperties",  "Components", etc.).

If you want to use them, you need to pass this objects to the external VB file as reference.

 

Local rule

 

AddVbFile "C:\Path\To\SetPartNumberExternal_iLogic.vb"

Dim extCode As New ExternalCode

'iProperties used below refers to the ThisDoc.Document properties.
extCode.SetPartNumber(iProperties)

 

 

SetPartNumberExternal_iLogic.vb

 

Class ExternalCode

	Public Sub SetPartNumber(iProperties As IiProperties)
		iProperties.Value("Project", "Part Number") = "New PartNumber"
	End Sub

End Class

 

 

Or you need to use standard Inventor API. I prefer this approach, but it depends on your needs.

 

Local rule

 

AddVbFile "C:\Path\To\SetPartNumberExternal_API.vb"

Dim extCode As New ExternalCode
extCode.SetPartNumber(ThisDoc.Document)

 

 

SetPartNumberExternal_API.vb

 

Class ExternalCode

	Public Sub SetPartNumber(doc As Inventor.Document)
        doc.PropertySets("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")("Part Number").Value = "New PartNumber"
	End Sub

End Class

 

 

Message 4 of 4
WCrihfield
in reply to: marcin_bargiel

Hi @marcin_bargiel.  It might help a little to know that there is a difference between the iLogic add-in's API (Link1, Link2) versus the main Inventor API.  Early on, when folks are attempting to automate things in Inventor through iLogic & VBA, it can be a bit confusing to separate them all out and tell which resource or term belongs to which code system.  There is a term used within the online help documentation called 'Rule Objects', which represents a bunch of variables that are declared and given values behind the scenes within every 'normal' iLogic rule we create, and are therefore readily available to us while we are working within most simpler codes in the iLogic Rule editor dialog.

 

Since these 'Rule Objects' are pretty much all some sort of Interface (Link1, Link2), instead of a Class (Link1, Link2, Link3), we can not simply create a new one using the 'New' keyword.  Due to how they are created for us, if we want to use them elsewhere (such as in externally referenced resources), we must 'pass' them to that other resource, one way or another, similar to what @Michael.Navara described above.  But it does not always need to be as an 'input' parameter to a method (Sub / Function routine).  If your external resource represents a custom Class, then that Class could have a Public Property containing both Get & Set functionality, then you could 'set' that property's value after creating a 'New' instance of that Class in your other rule.  Or you could have some sort of 'Initialize' type method defined within your Class, which when ran, asks for some of those 'Rule Objects' as inputs, then uses those to set the values of Private internal properties within the Class, that could then be used within all of its other internal tools.  There are lots of ways it could be done, but the main point is that the externally referenced Class will not recognize, or be able to use those 'Rule Objects' (because they were created elsewhere) until your 'regular rule' sends/passes them to it somehow.  But perhaps the more popular route would be to do everything in your referenced Class using Inventor API code, instead of using code that is unique to the iLogic add-in, then you would not need to send/pass anything like that to your externally referenced code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report