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: 

Get iProperty from BomRow

16 REPLIES 16
SOLVED
Reply
Message 1 of 17
cadman777
2072 Views, 16 Replies

Get iProperty from BomRow

Hello,

I'm trying to modify a rule that someone else made.

It gets the ItemQuantity from the BOMRow like this:

 

 

oQty = oQty + oBOMRow.ItemQuantity

 

 

I found BOMRow in Inventor VBA and it shows ItemQuantity as one of its properties.

It also shows ComponentDefinitions as one of its properties.

I figured I could use ComponentDefinitions to get the 'Design Tracking Properties': "Stock Number".

BUT, I can't figure out how to write it.

Help is appreciated...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
16 REPLIES 16
Message 2 of 17
A.Acheson
in reply to: cadman777

Here is some examples. It will depend at what level you are looking for the part assembly 

 

https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/ilogic-bom-qty-need-help-with-code/td-p...

 

if using iproperties snippet the most important thing to remember is the document name reference before the location of the iproperty. This will target where you are retrieving the iproperty from. “CompFileNameOnly” If not included the iproperty will be taken from the document the rule was run from. 

iProperties.Value(CompFileNameOnly, "Custom", "SO")

 

If you include a screenshot or description of where you want to run the rule and what info you want to capture I am sure a sample can be either found or created. As the recursive rules can be complex. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 17
cadman777
in reply to: A.Acheson

Thanx for the hint, and thanx for admitting that it can be complicated. I tried what you suggested, and it did get me further, but not far enough. There's something missing, and I think (but am not sure) that I need to add more lines to 'drill-down' from the Document all the way down to the Part level.

 

The problem is I don't know how to write lines of code. I WANT to learn, and have been trying since 2018 (during spare time), but just can't find the information I need to 'get it'. I've read and read for 100's of hours, worked through lessons, and more, but there is no structure to any of this that I can see. If there is structure to it, then I would like to read a book or do lessons that will teach me the structure (like English grammar: subject + predicate = complete sentence, or subject + predicate + object = complete sentence), so I can CONSTRUCT lines of code (programming sentences). ALL the lessons and books (like 'VBA for Dummies') do NOT teach that. Having gotten a degree as a teacher, I can tell you as a matter of FACT that all these people who write these books DO NOT KNOW HOW TO TEACH. They just run through concepts and topics that are packed into their heads, but don't TEACH the grammar/syntax of code writing. I get the feeling that they expect you to 'just get it' as you copy their scatter-brained code. But like TAX LAW, you just don't 'get it', b/c there's a myriad of underlying presumptions that are HIDDEN BEHIND the law that not even judges know. Same w/this code stuff. I need all those BASIC hidden rules for constructing sentences (lines of code).

 

Here's the macro I'm trying to make a very simple change to but can't figure out how to do it. It originally was like your post in getting the ItemQuantity from the BOMRow. I wanted to use that comprehensive 'flat list' to get the 'Stock Number' and do the same thing with it that the macro already does. So I figured I could change just one line and it would work. But if I knew the rules better, then I'd know if I needed to change add more lines in addition to changing that one line.  I trust you get what I'm telling you. Incidentally, if I knew how to do this, I would not be borrowing other people's code. I would write mine 'from scratch'. Here's the code:

 

'Get and Set 'Stock Number' in all parts in an assembly in a Custom iProperty named 'StkNum'

Class ThisRule
	Dim rDoc As Document
	Dim oDoc As Document
	Dim oSN As String

'access top-level assembly BOM
	Sub Main()
		On Error Resume Next
		Dim oAssem As AssemblyDocument = ThisDoc.Document
		Dim oBOM As BOM = oAssem.ComponentDefinition.BOM

		oBOM.StructuredViewFirstLevelOnly = False
		oBOM.StructuredViewEnabled = True
		oBOM.PartsOnlyViewEnabled = True
		oBOM.SetPartNumberMergeSettings(True, )

		For Each oDoc In oAssem.AllReferencedDocuments
			'run subs on BOM
			If oDoc.DocumentType = 12291 Then Call ListItems(oBOM.BOMViews.Item(1).BOMRows, 0, oDoc) 'assembly
			If oDoc.DocumentType = 12290 Then Call ListItems(oBOM.BOMViews.Item(3).BOMRows, 0, oDoc) 'part
		Next
	End Sub

	'extract total quantity from assembly and insert it into a new Cutsom iProperty "TotalQty"
	Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer, oDoc As Document)
		
		For Each oBOMRow As BOMRow In Rows
			rDoc = oBOMRow.ComponentDefinitions.Item(1).Document
				
			If rDoc IsNot oDoc Then
			
				If Not oBOMRow.ChildRows Is Nothing Then
					Call ListItems(oBOMRow.ChildRows, indent + 1, oDoc)
				End If
			Else	
' *****************************************************************************************************************************************
'This is what I tried to do using the BOM, but couldn't figure out how to get the iProperty out of the BOM. Is this possible to do?:
' *****************************************************************************************************************************************
				'oSN = oBOMRow.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value
' ****************************************************************************************************************************************************
'This is how I interpreted your instructions, but it didn't return any value, even though there is a value in the 'Stock Number' of every ipt file:
' ****************************************************************************************************************************************************
				oSN = iProperties.Value(rDoc, "Design Tracking Properties", "Stock Number")
' ****************************************************
'This is my check to see if the line returns a value
' ****************************************************
				MessageBox.Show(oSN, "Stock Number") 
				i=1
				For Each kDoc In oBOMRow.ComponentDefinitions					
					rDoc = oBOMRow.ComponentDefinitions.Item(i).Document
					rDoc.PropertySets.Item("Inventor User Defined Properties").Item("StkNum").Value = oSN
					i=i+1
				Next
			
			End If

		Next
	End Sub

End Class

 

Thanx for your help!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 4 of 17
WCrihfield
in reply to: cadman777

Here's the step you're missing.

create a document variable, then assign the first component definition's document (from that BOMRow) to it

Then you can access the usual PropertySets.PropertySet.Property.Value as normal from that document.

Dim oBOMRow As BOMRow '= whatever
If oBOMRow.ComponentDefinitions.Count > 0 Then
	Dim oRowDoc As Document = oBOMRow.ComponentDefinitions.Item(1).Document
	Dim oStockNum As String = oRowDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value
End If

 If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :light_bulb:or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 17
A.Acheson
in reply to: WCrihfield



@cadman777 

I think the BOM is probably one of the harder loops to grasp because of the amount of variables and levels. I have only started to dabble in here with the help of others work for guidance.  I like to use the occurrence looping as I can understand it better and it is more universal for other operations.  I would love to be at the code writing from scratch stage. I like to do this when I have time and can remember the steps. In normally ends up with some kind of searching in the help or the forum. I have no formal training in this, the same I am sure for a lot of the user in the forum and really spot things by memorizing where I had problems before and pointing them out. 
I have notice you have used a hybrid method to get the value of the iproperty stock number. You are using a combination of the property sets method and the ilogic method. Although it works (just tested the get iprop snippet on its own inside a document) I am not sure if this could give you problems else where.

 

 

 

 

oSN = iProperties.Value(rDoc, "Design Tracking Properties", "Stock Number")

 

 

 

I found this chart that list all the iproperties in a handy chart. Some of these vary from version to version 


https://adndevblog.typepad.com/manufacturing/2018/04/accessing-iproperties-through-ilogic-code.html

 

The typical method for ilogic iproperty snippet. 

 

 

 

oSN = iProperties.Value(rDoc, "Project", "Stock Number")

 

 

 

 

Long method for getting/setting properties.

 

 

 

Dim oStockNum As String = oRowDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value

 

 

 

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 6 of 17
cadman777
in reply to: A.Acheson

Thanx for your speedy reply!

 

I see, we're all scratching this out on the hard earth little by little.

Like one teacher used to say, 'the one-eyed man is king in the kingdom of the blind'.

 

Thanx for the explanation, it helps.

I didn't include all the tries I made at making that line of code work.

But I promise you that I tried all 3 methods of grabbing the iProperty in my code above, but none of them worked.

The main difference in the one example is, the variable declaration occurs at the top of the rule instead of in the immediate context of the line.

I have no idea what is stopping the line of code from getting that iProperty from the files.

 

Thanx for the properties chart.
I already have one, and it's always open when I'm doing this stuff.

My memory ain't what it used to be.

Same w/the Inventor VBA module, it's always open w/the Object's Browser open, and help readily available.

The thing that kicks my butt is that I can never finish the trail from the Inventor App all the way down to the Leaf and Property. Also, I don't know when to use Methods or Functions, or what the difference is when looking at other people's rules. I ALWAYS get stuck right near the end of a line of code b/c I don't know where to look up the rest of the drill-down trail that leads me to the end. Basically, what I need is a library of code samples that tell me how to do this or that. Just simple short samples like yours above, as well as simple concise explanations of how to do one thing or another. Those long VBA samples in the help file are good if they work exactly how I need them to work.  But they NEVER do. One reason I'm doing this rule is to change all the iProperties to a static value to see if another rule isn't working right. But now I'm 2 levels deep in this sh*t and am getting deeper all the time, which no solution in sight. This is just like dealing with the g.d. tax lawyers and their interpretation and use of the Tax Code (which is nearly always WRONG, even though they nearly always WIN!).

 

Anyway, do you know where I can find samples and explanations that I need?

I already know and have looked at the pages on Mod the Machine and other web sites dedicated to this stuff, but they don't help much b/c I can't figure out how to combine them, and also I still need to learn how to construct a code sentence syntactically correctly. I know exactly what I need to learn, but don't know where to learn it. And all the past AU courses I read or watched as videos didn't do much to help me get there. AU training for beginners SUCKS.

 

Anyway, thanx for the help.

 

Have you tried running my rule on any of your assemblies to see if it works for you?

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 7 of 17
cadman777
in reply to: WCrihfield

Thanx for this info.

Let me try it out and see if it works.

First I need to see if I know how to incorporate it into my rule...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 8 of 17
cadman777
in reply to: WCrihfield

Your instructions are basically what I said above, but in different words.

But I still don't know how to construct the code for that.

 

1. I just tried your code and it threw this error:

'Error on Line 39: Variable 'oBOMRow' hides a variable in an enclosing block'.

Here's what MS says it means:

 

  • Another common source of this error is an attempt to access a local variable declared within a Try block in a separate Catch block. To correct this, declare the variable outside the Try...Catch...Finally structure.

Other Questions:

2. What is 'whatever' supposed to refer back to or forward to?

3. Dim oBOMRow As BOMRow is already declared above the 'For Each' line, so why duplicate it?

I'm guessing that's why that error pops up.

4.  If I Comment-out that duplicate declaration line, the code runs but does the same thing as the other code attempts: The MessageBox pops up and is empty, which tells me that code didn't access the file's iProperty.

 

Did you try your suggestion on this rule, and run on one of your assemblies to see if it works for you?

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 9 of 17
cadman777
in reply to: cadman777

Here's the finalized rule:

 

 

'Gets "Stock Number" of all parts in assembly and writes that value into the iprop named "StkNum" in each part

Class ThisRule
	Dim rDoc As Document
	Dim oDoc As Document
	Dim oSN As String

'access top-level assembly BOM
	Sub Main()
		On Error Resume Next
		Dim oAssem As AssemblyDocument = ThisDoc.Document
		Dim oBOM As BOM = oAssem.ComponentDefinition.BOM

		oBOM.StructuredViewFirstLevelOnly = False
		oBOM.StructuredViewEnabled = True
		oBOM.PartsOnlyViewEnabled = True
		oBOM.SetPartNumberMergeSettings(True, )

		For Each oDoc In oAssem.AllReferencedDocuments
			'run subs on BOM
			If oDoc.DocumentType = 12291 Then Call ListItems(oBOM.BOMViews.Item(1).BOMRows, 0, oDoc) 'assembly
			If oDoc.DocumentType = 12290 Then Call ListItems(oBOM.BOMViews.Item(3).BOMRows, 0, oDoc) 'part
		Next
	End Sub

	'extract total quantity from assembly and insert it into a new Cutsom iProperty "TotalQty"
	Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer, oDoc As Document)
		
		For Each oBOMRow As BOMRow In Rows
			rDoc = oBOMRow.ComponentDefinitions.Item(1).Document
			If rDoc IsNot oDoc Then
			If Not oBOMRow.ChildRows Is Nothing Then
				Call ListItems(oBOMRow.ChildRows, indent + 1, oDoc)
			End If
			
			Else	

'***************************************** Added & mofified from Inventor online Help Added from Inventor online Help **************************************************************************************************************************************************************** 		
			Dim oCompDef As ComponentDefinition
			oCompDef = oBomRow.ComponentDefinitions.Item(1)
			'The required property set is named "Design Tracking Properties." Obtain this from the owning document of the component.
			Dim oPropSet As PropertySet
			oPropSet = oCompDef.Document.PropertySets.Item("Design Tracking Properties")
			'Now we have all the information necessary to list the BOM content. Obtain variable information such as the item number _
			'and quantity from the BOMRow object, and the part number and description from the property set.
'				MessageBox.Show("#: " & oBomRow.ItemNumber & _
'				" Quantity:" & oBomRow.ItemQuantity & _
'				"Part Number: " & oPropSet.Item("Part Number").Value & _
'				" Description: " & oPropSet.Item("Description").Value & _
'				" Stock Number: " & oPropSet.Item("Description").Value)
'				MessageBox.Show(" Stock Number: " & oPropSet.Item("Stock Number").Value)
				Dim oSN As String = oPropSet.Item("Stock Number").Value
'***************************************** Added & mofified from Inventor online Help **************************************************************************************************************************************************************** 
				i=1

				For Each kDoc In oBOMRow.ComponentDefinitions					
					rDoc = oBOMRow.ComponentDefinitions.Item(i).Document
					rDoc.PropertySets.Item("Inventor User Defined Properties").Item("StkNum").Value = oSN
				i=i+1
				Next
			End If
		Next
	End Sub
End Class

 

 

I based this on the advice given by everybody who contributed as follows:

 

@A.Acheson" the most important thing to remember is the document name reference before the location of the iproperty".

[That reminder was a key that I never realized before. IOW, you have to make sure you identify which Inventor document you're working from in your line of code.]

 

@WCrihfield "...create a document variable, then assign the first component definition's document (from that BOMRow) to it".

[That cued me in on another thing I hadn't learned yet. My new mantra for that is, 'first declare it then assign it'.]

 

@A.Acheson "I have notice you have used a hybrid method to get the value of the iproperty stock number. You are using a combination of the property sets method and the ilogic method...The typical method for ilogic iproperty snippet...Long method for getting/setting properties."

[That helped me organize methods for one operation, which helped to dispel confusion about what is going on with differing methods.]

 

So I took the above advice, along with VB.Net Inventor Help examples, and combined them with an existing iLogic rule, and with a little adapting of the VB.Net to iLogic, got the rule to work. I wonder if it will work for others? All they have to do is open an assembly and change the iProperty names if so desired.

 

Incidentally, you'll notice in the below screenshot two columns for 2 iProperties (Stock Number and Item QTY). Inventor forced me to do that b/c in my drawing View Label where an iLogic rule creates the label showing the Qty Req'd, when pulling from 'Item QTY' the rule sometimes won't see a total quantity, and reports the wrong number or resorts to "1". When there's 500+ parts to detail, all that error does is add to the work load! So the way I got around that was to use someone's suggestion in this forum and make a plain text column by copying the values out of the native Inventor iProperty column, and pasting them into a substitute iProperty column. Then query that sub col to get the numbers for the View Label. It worked. So I wanted to try that with a rule that sorts all parts in an assembly by Stock Number. It wasn't working when querying the native Inventor 'Stock Number' iProperty, so now I can try using a substitute iProperty to get what I want out of that rule. Gotta luv these zillions of work-arounds to do just one simple thing!

 

Anyway, here's the results of the above rule:

cadman777_0-1628437316981.jpeg

 


Thanx for the help!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 10 of 17
cadman777
in reply to: cadman777

Oops! One thing I forgot to add:

The above rule needs to be run AFTER this rule:

 

'Rule by Curtis W. (as-modified) - Open top-leval assembly file and run
'rule to add custom iproperty named "TotalQty" to BOM if it doesn't exist

'activate iLgic run rule automation
Dim addIn As ApplicationAddIn
Dim addIns As ApplicationAddIns = ThisApplication.ApplicationAddIns
Dim iLogicAuto
For Each addIn In addIns
    If InStr(addIn.DisplayName, "iLogic") > 0 Then
        iLogicAuto = addIn.Automation
        Exit For
    End If
Next

'open and activate assembly file
Dim openDoc As Document
openDoc = ThisDoc.Document

Dim docFile As Document

If openDoc.DocumentType = kAssemblyDocumentObject Then    
	For Each docFile In openDoc.AllReferencedDocuments
'****Add your full path and filename****
		iLogicAuto.RunExternalRule(docFile, "Add your full path\IPT_CHECK_ADD_IPROP_StkNum_OPEN_PART")
	Next
	Else
	MessageBox.Show("You must have a valid Assembly document open before using this code!", "File Type Mismatch!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
End If

 

Which runs the attached rule.

This rule checks for the existence of the iProperty in a part file, and if it doesn't exist, it adds it.

The above rule transfers the Value of the given iProperty into the new iProperty that this rule created for you.

So you have to run these rules in order.

I haven't gotten around to figuring out how to run them both in this run file.

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 11 of 17
A.Acheson
in reply to: cadman777

Nice work on getting this to work. Lots of learning happening which great. I read something about a view and drawing in your last post  so I am wondering  is this end goal to get the stock number and qty into the view label of the drawing where the drawing sheet holds multiple parts from the same assembly with view reps used? I just finished up a rule to do this yesterday so it could help. The rule ensures the view label is visible and view is associative and places all view reps on the sheets then cycles through each view ,makes the part name equals to view rep name, reads the BOM and cross references view rep name to the part number and if it matches places the qty in the view label. 

AAcheson_1-1628448778305.png

 

If your able to give us a picture of the whole workflow then likely the rules can be consolidated and maybe you can eliminate some of the extra iprops once we know what errors are coming up and how to deal with them.

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 12 of 17
cadman777
in reply to: A.Acheson

Thanx! It took some learning, but it was my first 'victory' over this b.s. that Autodesk has forced me to do (which really is THEIR job!). But thanx for the help, b/c it got me moved one more step closer to where I'm trying to go.

 

Yes, that approximates what I'm trying to accomplish. At the heart of it I'm trying to establish a way to list ALL of the parts in a top level assembly, then sort them, then filter them, so I can do various things with the resulting list, for example:

 

1. Create a new drawing and lay down all flatpattern views to fill up the sheet, and when it gets filled, open another drawing and repeat until all flatpattern views are created. I have a rule that sort of does that, but it skips some sheetmetal parts and adds some parts that are not sheetmetal parts. I have no idea why it does that or how to fix it. I've tried a number of things but none of them work.

 

2. Create a new drawing and lay down all single part detail views, with each part having an end view, r.h. view and view above the r.h. view, with the view label being under the first view (the end view). I tried to accomplish this using the knowledge that Mod the Machine and Mfgr's DEV Blog provide, along with Inventor Help, but I just can't figure out how to place the views a certain distance apart, or fill up a sheet, or any of the other stuff like above.

 

3. Update all view labels on a sheet full of flatpattern or detail drawings showing total quantity of parts required for the entire project (as well as other iProperties). I already have a rule that somewhat does that, but it always skips some parts in a big project. I have no idea why it does that or how to fix it. I've tried a number of things but none of them work.

 

4. The kinds of projects that cause me the most trouble making details are those were there are multiple sub-assemblies that use the same part file, or use a part file of different name but same everything else (created by FG and rolled up in the total parts BOM). For some reason I always have problems with the view labels updating or the flatpattern drawing views. This particular problem is one of the reasons I tried doing this using the BOM, b/c I read in one of the expert's web sites (can't recall where) that the BOM is where you can get a TRUE and FLAT list of all the parts, just like in the Parts Only BOM. I already tried 'AllReferencedParts', but that didn't work, so I tried the BOM method and it seems to work, somewhat. But figuring out why some things don't work is ridiculous, due to the amount of novice work that goes into troubleshooting such a thing.

 

Anyway, those are the kinds of things I'm trying to accomplish, and other things as well, such as automating the creation of structural connections, structural weldments, etc.

 

Thanx for helping!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 13 of 17
WCrihfield
in reply to: cadman777

Sorry for not getting back to you on Friday @cadman777. I tried to respond at least a dozen times on Friday, but it would never finish going through, because I kept continually getting signed out of my account on the forums. ‌😖‌ It was extremely frustrating, and I tried all sorts of things, including closing and restarting my browser, but it seemed like it wouldn't maintain my 'signed-in' status past a single new tab, or tab refresh, of clicking through a link or two. I eventually just had to give up. ‌😓‌  (I'm still having some less severe issues like this today.)

After hearing your confusion about my last post, I wanted to immediately explain in much more detail, and had a mostly rewritten version of your whole code to post this time, instead of just a small snippet, but as I said above, it just wouldn't make it through the response process. I have experienced similar episodes before here on the forums too, but I still have no idea what causes it to happen.

I'm glad to hear that you eventually got the code working the way you intended though. ‌🙂

Some of those code snippets that are defined within iLogic only, for working with the iProperties & parameters, can provide a 'shortcut' method of doing some things, and area great for some of the simpler scenarios. However, I've grown to be very cautious about using them in most other more complex scenarios, in favor of doing things the normal (longer) route. Any time I can supply an already defined document variable for a method (Sub or Function) to target/affect, I greatly prefer this and know it will be more stable in the long run, verses a method that just always points to whichever document just happens to be 'active' at that moment.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 14 of 17
cadman777
in reply to: WCrihfield

Thanx for the effort!

 

Yeah, this forum has been sucking for many months now, and it's not getting any better. One would think that with all the REVENUES that Autodesk rakes in annually, and with how badly their VAR support sucks (and always has!), that they could at least keep their Help Forum working well so we can get the answers we need. Anyway...

 

You talk about things I need to learn, but I have not idea where or how to learn them. I'm beginning to grow tired of hacking away trying this or that to see if I can happen upon some code that works. That's the stupidest way to do anything, ever. So I just want to learn this stuff without having to take a college course in it. And I don't want to just memorize everything like I did when I was young, b/c I don't have that capacity any longer. I need to learn the structure and syntax, and when to do what, how. Far as I'm concerned, coding is a clusterf**k of personality. Few people know how to write good programs, from what I've seen in the industry. In fact, one place I worked, I sat next to a guy who was an expert at C++ VB.Net, etc., and also did WonderWare for the local production plants, and when he got on the phone w/the MicroSnot tech people, he ended up cussing them out and teaching them the things they didn't even know so they could talk to their highest up experts to see if they could get an answer for him, which nearly never came. What's that tell you about programmers in the 'industry'? I can tell plenty of stories...

 

At this point, I'm inclined to do this in VB.Net, but that appears to be a huge learning curve. I'm trying to do it in Inventor VBA, but nearly all my Inventor rules are done in iLogic, or a mix of iLogic + VBA. So really, I'm kind of stuck between two worlds, which is Autodesk's doing, NOT MINE.

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 15 of 17
cadman777
in reply to: A.Acheson

Hi Alan,

I"m revisiting this subject and found this thread.

Your rule looks very interesting.

Any chance I can have a look at it?
Maybe I can learn something useful to my work-flow!

Cheers...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
Message 16 of 17
A.Acheson
in reply to: cadman777

Here is two rules I am using for drawings with view reps. They seem to work well. You may need to do some customizing  of rule 1 as  there is a filter to only create views with certain names. "If oDesView.Name.Contains("SP") Then", so simply remove the if statement for all view reps. 

 

  1. Views created from view reps
'https://forums.autodesk.com/t5/inventor-customization/ilogic-drawing-view-height-and-size-problem/td-p/9256794
'https://forums.autodesk.com/t5/inventor-forum/place-all-design-views-on-an-idw/td-p/6035731

Sub Main
	CreateViewForEachRep()
End Sub
Public Sub CreateViewForEachRep()
    ' Set a reference to the drawing document.
    ' This assumes a drawing document is active.
    Dim oDrawDoc As DrawingDocument
     oDrawDoc = ThisApplication.ActiveDocument
    
    'Set a reference to the active sheet.
    Dim oSheet As Sheet
     oSheet = oDrawDoc.ActiveSheet
    
    Dim viewScale As Double
     viewScale = 1/20
    
    Dim ptx As Long
     ptx = 0
	 
    'this assumes that view1 is of the full assembly - a view must have been placed in a drawing before running this
    Dim assyDocName As String
     assyDocName = oSheet.DrawingViews.Item(1).ReferencedDocumentDescriptor.FullDocumentName
        
    Dim assyDoc As AssemblyDocument
    'open assembly doc invisibly
     assyDoc = ThisApplication.Documents.Open(assyDocName, False)
        
    Dim oAssyCompDef As AssemblyComponentDefinition
     oAssyCompDef = assyDoc.ComponentDefinition
    
    Dim oRepMgr As RepresentationsManager
     oRepMgr = oAssyCompDef.RepresentationsManager
    
    Dim oDesView As DesignViewRepresentation
    
    For Each oDesView In oRepMgr.DesignViewRepresentations
     
           If oDesView.Name.Contains("SP") Then
			   
            Dim oPoint1 As Point2d
             oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(ptx, 11)
            
            Call PlaceBaseView(oSheet, assyDoc, oPoint1, oDesView.Name,viewScale)
              
        End If
        ptx = ptx + 6
		'ptx = ptx + 2 +(VWidth/2)
    Next
      
      'close assembly doc
      assyDoc.Close (False)
      
End Sub

Public Sub PlaceBaseView(ByRef sheet As Inventor.Sheet, _
                        ByRef assyDoc As AssemblyDocument, _
                        ByRef oPoint1 As Point2d, _
                        ByRef viewName As String, _
						ByRef viewScale As Double)

    'define view orientation
    Dim vieworient1 As ViewOrientationTypeEnum
     vieworient1 = ViewOrientationTypeEnum.kFrontViewOrientation

    'define view style
    Dim viewstyle1 As DrawingViewStyleEnum
     viewstyle1 = DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle
   
    Dim oFaceView As DrawingView
	
     oFaceView = sheet.DrawingViews.AddBaseView(assyDoc, oPoint1, viewScale, vieworient1, viewstyle1, viewName)'viewScale
	 
	 'Set view reps associative so they update when model changes. Othewise they are a static image
	oFaceView.SetDesignViewRepresentation(viewName,True)
End Sub

 

2. Set View Labels based on ViewRep

AAcheson_0-1637022477887.png

 

'https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/ilogic-math-function-to-see-what-lenght-fits-the-best/td-p/10511825
Sub Main
	
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDrawing.Document
Dim oModel As AssemblyDocument
oModel = ThisDoc.ModelDocument
Dim NameQty As New Dictionary(Of String, Double)
Dim sViewRepNames As New ArrayList
Dim oSheets As Sheets
Dim oSheet As Sheet
Dim oViews As DrawingViews
Dim oView As DrawingView
Dim MFGQTY As String
Dim sViewRepName As String 

oSheets = oDrawDoc.Sheets
Dim i As Integer = 0

Call TraverseBOM(oModel, NameQty)

For Each oSheet In oSheets
	oViews = oSheet.DrawingViews
	
    For Each oView In oViews
		'make view label visible
		 oView.ShowLabel = True
		Try
		sViewRepName = oView.ActiveDesignViewRepresentation.ToString
		'MessageBox.Show(sViewRepName, "Title")
		sViewRepNames.Add(sViewRepName)
		Catch
			MessageBox.Show("View Rep not associative" , "Title")
		End Try
		
		For Each pair As KeyValuePair(Of String, Double) In NameQty
		If pair.Key = sViewRepName Then
			If pair.Value = 1 Then
				
				sString1 = "<DrawingViewName/>"
				sString2 = sViewRepName 
				'sString3 = "QTY: " & pair.Value 
				
				'add lines to the view label
				'break line using:  "<Br/>" 
			    oView.Label.FormattedText = _
			    sString1 & "<Br/>" & _
			    sString2 & "<Br/>" '& _
				'sString3 & "<Br/>"	
					
			ElseIf pair.Value > 1 Then
				sString1 = "<DrawingViewName/>"
				sString2 = sViewRepName 
				sString3 = "QTY: " & pair.Value 
				
				'add lines to the view label
				'break line using:  "<Br/>" 
			    oView.Label.FormattedText = _
			    sString1 & "<Br/>" & _
			    sString2 & "<Br/>" & _
				sString3 & "<Br/>"	
			End If
		End If
	
		Next
	Next
	
Next
d0 = InputListBox("Prompt", NameQty, d0, Title := "Title", ListName := "List")
d0 = InputListBox("Prompt", sViewRepNames, d0, Title := "Title", ListName := "List")
End Sub

Public Sub TraverseBOM(oModel, NameQty )

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = oModel.ComponentDefinition

'[Traverse the BOM
'https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/ilogic-get-properties-from-bom/td-p/9204275
For Each oBOMView As BOMView In oAsmCompDef.BOM.BOMViews
	'Logger.Info("looping through BOM")
	If oBOMView.ViewType = BOMViewTypeEnum.kStructuredBOMViewType Then
		On Error Resume Next
		For Each oBOMRow As BOMRow In oBOMView.BOMRows
			Dim oDoc As Document = oBOMRow.ComponentDefinitions.Item(1).Document
			'Logger.Info(oDoc.DisplayName)
			Dim oDTP As PropertySet = oDoc.PropertySets.Item("Design Tracking Properties")
			'Dim oItemNum As String = oBOMRow.ItemNumber
			Dim oPN As String = oDTP.Item("Part Number").Value.ToString
				
			Dim oDesc As String = oDTP.Item("Description").Value.ToString
			Dim Qty As String = oBOMRow.TotalQuantity
			
			'Deal with non numeric qty in BOM
			numericCheck = IsNumeric(Qty)
			If numericCheck = True Then
				'Add to dictionary of string,double
				'Note, the string part is so we can return a reference later.
				NameQty.Add(oPN, Qty)
			 
			Else
			'MessageBox.Show("Input is NOT numeric.", "iLogic")
			End If
		Next
		']
	    	
	End If
Next

End Sub

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 17 of 17
cadman777
in reply to: A.Acheson

Alan, thanx for sharing this rule w/me!

Also, thanx for the links (great idea to include in your rule).

Just read them all and see they fill in the blanks of what I wanted to know for some time.

Nice!

 

Gonna analyze this today to see what I can learn from you.

 

The other day I decided to revisit the way I do 'automatic drawings' for flat patterns. I simplified it greatly by using an idw template that sets up all the label text using unused native Inventor iProperties. I have a couple rules (modified forum work) that insert the custom iProperties into each ipt file's native iProperties, and then opens that idw template and populates it w/flat pattern views with the template's standard label. Works like a charm. So simple, but took 2 years of fiddle farting around w/iLogic to understand how to do that.

 

Anyway, I'm looking forward to seeing how you did your views, b/c I still haven't figured out how to make a rule to automatically make drawings views of all my detail parts.

 

Cheers...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report