Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
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: 

Ilogic level of detail representation in drawing template

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
611 Views, 3 Replies

Ilogic level of detail representation in drawing template

I have a problem.
I use drawing template with ilogic rules which copy parameters of linked model into drawing and then into the title block. For example:

 
Dim openDoc As Document
openDoc = ThisDoc.Document
Dim docFile As Document
If ThisDoc.ModelDocument IsNot Nothing Then
docFile = ThisDoc.ModelDocument
Else

Return
End If
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)
Dim docFName As String
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)

VyberM = iProperties.Material(docFName)
 

In docFName is saved the path to linked model file. But when model file is assembly with another level of detail representation than "main", the iLogic rule does not work. Is there any possibility to make the rule working with another level of representation? Or it is possible to make such a rule, which detects another level of detail representation than "main" in linked model and write error message?
Thanks for helping 🙂

3 REPLIES 3
Message 2 of 4
MechMachineMan
in reply to: Anonymous

It should work just fine using the file names. iProperties and parameters are stored in the master document, not any LODs.

 

Seeing more complete code would be cool.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
Message 3 of 4
Anonymous
in reply to: MechMachineMan

There is full code of rule that rewrites parameters from model to drawing

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 29329 StartFragment: 314 EndFragment: 29297 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

trigger = iTrigger0
'Definuje otevřený dokument
Dim openDoc As Document
'Prvni spusteni: 1 pravda, 0 nepravda
openDoc = ThisDoc.Document
'Zjistí soubor modelu, na který se odkazuje výkres
Dim docFile As Document
If ThisDoc.ModelDocument IsNot Nothing Then
docFile = ThisDoc.ModelDocument
Else

Return
End If
'format model file name
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)
Dim docFName As String
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
'define the property set
customPropertySet = docFile.PropertySets.Item("Inventor User Defined Properties")
'look for the custom propety and add it if not found
Try
prop = customPropertySet.Item("VyberM")
Catch
customPropertySet.Add("", "VyberM")
End Try
'get total area of model

'start radio box with questions

'napřed přepsání hodnot z modelu do razítka





Datum_zmeny_1 = iProperties.Value(docFName, "Custom", "Datum změny 1")
Datum_zmeny_2 = iProperties.Value(docFName, "Custom", "Datum změny 2")
Datum_zmeny_3 = iProperties.Value(docFName, "Custom", "Datum změny 3")
Datum_zmeny_4 = iProperties.Value(docFName, "Custom", "Datum změny 4")

Index_zmeny_1 = iProperties.Value(docFName, "Custom", "Index změny 1")
Index_zmeny_2 = iProperties.Value(docFName, "Custom", "Index změny 2")
Index_zmeny_3 = iProperties.Value(docFName, "Custom", "Index změny 3")
Index_zmeny_4 = iProperties.Value(docFName, "Custom", "Index změny 4")

Zmena_1 = iProperties.Value(docFName, "Custom", "Změna 1")
Zmena_2 = iProperties.Value(docFName, "Custom", "Změna 2")
Zmena_3 = iProperties.Value(docFName, "Custom", "Změna 3")
Zmena_4 = iProperties.Value(docFName, "Custom", "Změna 4")

Nahrazuje = iProperties.Value(docFName, "Custom", "Nahrazuje")
Norma_PU = iProperties.Value(docFName, "Custom", "Norma PÚ")
Nazev_Rozmer = iProperties.Value(docFName, "Custom", "Název-Rozměr")
If Nazev_Rozmer <> Sestava  Then
If Nazev_Rozmer <> SVAŘENEC Then
    iProperties.Value(docFName, "Custom", "Materiál") = Materiál
End If
End If
Materiál = iProperties.Value(docFName, "Custom", "Materiál")
Polotovar = iProperties.Value(docFName, "Custom", "Polotovar")
Povrchova_uprava = iProperties.Value(docFName, "Custom", "Povrchová úprava")
Pozice_v_sestave = iProperties.Value(docFName, "Custom", "Pozice v sestavě")
Poznamka_PU = iProperties.Value(docFName, "Custom", "Poznámka-PÚ")

It works even if model doesnt have the same parameters as it is written in this rule. But it doesnt work with assembly, that uses another LOD than main.
And there is the rule, which rewrites parameters of model by the parameters of drawing. In the title block, parameters of model are used. Every parameter there is text parameter.

Format:HTML Format Version:1.0 StartHTML: 165 EndHTML: 30086 StartFragment: 314 EndFragment: 30054 StartSelection: 314 EndSelection: 314SyntaxEditor Code Snippet

'Definuje otevřený dokument
Dim openDoc As Document
openDoc = ThisDoc.Document
'Zjistí soubor modelu, na který se odkazuje výkres
Dim docFile As Document
If ThisDoc.ModelDocument IsNot Nothing Then
docFile = ThisDoc.ModelDocument
Else
Return
End If
'format model file name
Dim FNamePos As Long
FNamePos = InStrRev(docFile.FullFileName, "\", -1)
Dim docFName As String
docFName = Right(docFile.FullFileName, Len(docFile.FullFileName) - FNamePos)
'define the property set
customPropertySet = docFile.PropertySets.Item("Inventor User Defined Properties")
'look for the custom propety and add it if not found
Try
prop = customPropertySet.Item("VyberM")
Catch
customPropertySet.Add("", "VyberM")
End Try


iProperties.Value(docFName, "Custom", "VyberM") = VyberM

iProperties.Material(docFName) = VyberM

iProperties.Value(docFName, "Project", "Part number") = Cislosoucasti
iProperties.Value(docFName, "Summary", "Title") = Nazev

'Datum změny
iProperties.Value(docFName, "Custom", "Datum změny 1") = Datum_zmeny_1
iProperties.Value(docFName, "Custom", "Datum změny 2") = Datum_zmeny_2
iProperties.Value(docFName, "Custom", "Datum změny 3") = Datum_zmeny_3
iProperties.Value(docFName, "Custom", "Datum změny 4") = Datum_zmeny_4

'Index změny
iProperties.Value(docFName, "Custom", "Index změny 1") = Index_zmeny_1
iProperties.Value(docFName, "Custom", "Index změny 2") = Index_zmeny_2
iProperties.Value(docFName, "Custom", "Index změny 3") = Index_zmeny_3
iProperties.Value(docFName, "Custom", "Index změny 4") = Index_zmeny_4

'Změna
iProperties.Value(docFName, "Custom", "Změna 1") = Zmena_1
iProperties.Value(docFName, "Custom", "Změna 2") = Zmena_2
iProperties.Value(docFName, "Custom", "Změna 3") = Zmena_3
iProperties.Value(docFName, "Custom", "Změna 4") = Zmena_4


iProperties.Value(docFName, "Custom", "Materiál") = Materiál
iProperties.Value(docFName, "Custom", "Nahrazuje") = Nahrazuje
iProperties.Value(docFName, "Custom", "Norma PÚ") = Norma_PU
iProperties.Value(docFName, "Custom", "Název-Rozměr") = Nazev_Rozmer
iProperties.Value(docFName, "Custom", "Polotovar") = Polotovar
iProperties.Value(docFName, "Custom", "Povrchová úprava") = Povrchova_uprava
iProperties.Value(docFName, "Custom", "Pozice v sestavě") = Pozice_v_sestave
iProperties.Value(docFName, "Custom", "Poznámka-PÚ") = Poznamka_PU


Thank you for helping me. 
 

Message 4 of 4
daniel.puchta
in reply to: Anonymous

Hi MechMachineMan,

I had similar problem. What I suggest you is to have in your sheet View in which you have Main level of detail representation. Instead of defining the ModelDocument by 

docFile = ThisDoc.ModelDocument

define it using the View. Basically what I am doing is to: If the model document is assembly, chech the level of detail represenatiton. If main view has different level of detail representation, check all views with whe same model on the sheet. If there is view which has the main level of detail representation, use it for defining the model document. If there is no such view, create it outside of the area of sheet border.

There is my code:

If ThisDoc.Document.DocumentType = kDrawingDocumentObject Then 'Ověření, zda typ dokumentu je výkres - vhodné pro externí pravidla
	
	Else
		MessageBox.Show("Lze spustit pouze v otevřeném výkrese",iLogicVb.RuleName,MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
		Exit Sub
End If
'iLogicVb.RunRule("Aktualizace spolecnych iVlastnosti modelu na zaklade vykresu")
Dim oDoc As DrawingDocument 'Definování dokumentu jako dokumentu výkresu	
oDoc = ThisApplication.ActiveDocument 'dokument = aktivní dokument

Dim oSheet As Sheet = oDoc.ActiveSheet 'list = aktivní list
Dim oView As DrawingView
oView = oSheet.DrawingViews(1)
OrigModel = oView.ReferencedDocumentDescriptor.ReferencedDocument 'Model hlavního pohledu
Dim Hlavnipohled As Boolean = False 'Slouží pro určení, zda list má pohled s modelem hlavního pohledu, který je v úrovni detailu hlavní (u sestavy) - nebo který lze použít pro zapisování ivlastnosti (u součásti)

If OrigModel.DocumentType = 12291 'Pokud je model hlavního pohledu sestava, tak:
		ActLOD = oView.ActiveLevelOfDetailRepresentation 'Definování úrovně detailu hlavního pohledu
		'MessageBox.Show(ActLOD,"Úroveň detailu")
		'MessageBox.Show("Spravně","Ilogic")
		If ActLOD <> "Main" Then 'Pokud je uroven detailu hlavního pohledu jiná než hlavní:
			Hlavnipohled = False
			For Each oView2 In oSheet.DrawingViews 'Zjisti, zda se na listu nenachází pohled, kde je vložen model hlavního pohledu, ale v úrovni detailu hlavní
				If oView2.ReferencedDocumentDescriptor.ReferencedDocument.FullFileName = OrigModel.FullFileName 'prováděj pouze pro pohledy se stejným dokumentem jako s originálním pohledem
					ActLOD = oView2.ActiveLevelOfDetailRepresentation 'Uroven detailu prave porovnávaneho pohledu
					If ActLOD = "Hlavní" Then 'Pokud je uroven detailu prave porovnavaneho pohledu hlavní, tak:
						oView = oView2 'Definuj pohled pro zapisování iVlastností jako pravě porovnavany pohled
						Hlavnipohled = True 'Nyní je definovaný pohled, který lze použít pro definování iVlastností
					End If
				End If
			Next
		End If
	Else
		Hlavnipohled = True 'Pokud je model hlavního pohledu jiný než sestava, lze hlavní pohled použít pro zapisování iVlastností
End If
'MessageBox.Show(Hlavnipohled,"Hlavní pohled: ")
If Hlavnipohled = False 'Pokud platí, je ve výkrese pohled s modelem hlavního pohledu, který má hlavní úroveň detailu
	'MessageBox.Show("Chyba","Ilogic")
	Dim oViewLoc As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(50, 50) 'Definice bodu vložení pohledu
	oViewNovy = oSheet.DrawingViews.AddBaseView(OrigModel, oViewLoc, 1, ViewOrientationTypeEnum.kDefaultViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle) 'Definice pohledu
	NovyLOD = oViewNovy.ActiveLevelOfDetailRepresentation 'Uroven detailu nově vloženého pohledu
	Dim nejvetsirozmer As Double 'Určení, zda je šířka vyšší než výška 
	If oViewNovy.Width > oViewNovy.Height
		nejvetsirozmer = oViewNovy.Width
		Else
			nejvetsirozmer = oViewNovy.Height
	End If
		oViewNovy.Scale = 10/nejvetsirozmer 'určení měřítka pohledu
	If NovyLOD <> "Hlavní" 'Pokud je uroven detailu nově vloženého pohledu jiná než hlavní, přepni ji na hlavní
		oViewNovy.ActiveLevelOfDetailRepresentation = "Hlavní"
	End If
	oView = oViewNovy 'Pohled pro zapisování je nově vložený pohled
Else 'Zde se vklada pohled s modelem hlavního pohledu, který ale má hlavní úroveň detailu
	
	
End If

'Konec kodu pro kompatibilitu s urovněmi detailů______________________________________________________________________________________________________________________________



Dim oModelDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument	 	'definování dokumentu modelu jako modelu

 

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

Post to forums  

Autodesk Design & Make Report