Link between view Representation and Positional representation via ilogic

Link between view Representation and Positional representation via ilogic

k14348
Advocate Advocate
5,071 Views
13 Replies
Message 1 of 14

Link between view Representation and Positional representation via ilogic

k14348
Advocate
Advocate

Hi,

  I hav 6 Nos. View representation (Lets Call A,B,C,D,E,F) and 6 Nos. of Positional Representation(Lets cal A,B,C,D,E,F) . I want to link this two. Whenever i activate View Rep A automatically positional Rep should be activated via iLogic. Can anybody help?

 

-karthikeyan M

 

Note:-

Reference picture attached.

0 Likes
Accepted solutions (1)
5,072 Views
13 Replies
Replies (13)
Message 2 of 14

pball
Mentor
Mentor

Here is some iLogic code to set the view rep based on the positional rep. I have it triggered with any model parameter change. Not sure if it's possible to set the positional rep based on the view rep with the triggers available.

 

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

If oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name = "Master" Then 
	oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").activate
Else
	Try 
		oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name).activate
	Catch
		oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").activate
	End Try
End If
Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 3 of 14

k14348
Advocate
Advocate

Hi,

  u have done it for one representation . But i need for more than one rep.

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

If oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name = "Position1" Then 
	oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("View1").activate	
Else
	Try 
		oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name).activate
	Catch
		oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").activate
	End Try
End If

If oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name = "Position2" Then 
	oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("View2").activate	
Else
	Try 
		oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name).activate
	Catch
		oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").activate
	End Try
End If
If oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name = "Position3" Then 
	oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("View3").activate	
Else
	Try 
		oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name).activate
	Catch
		oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").activate
	End Try
End If

I tried something but its not working . Please solve this error.

 

-karthikeyan M

 

 

0 Likes
Message 4 of 14

pball
Mentor
Mentor

Actually my code works for any representation, as long as the view rep and pos rep are named the same. It seems you don't understand the logic so I'll break it down.

 

 

 

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

If oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name = "Master" Then 
'If the pos rep is the Master then activate the Default view rep oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").activate Else Try
'Try to active a view rep with the same name as the active pos rep
'So if "two" is the current pos rep it will try to active the view rep "two" oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name).activate Catch
'If a view rep with the same name as the active pos rep doesn't exist set the default view rep active oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").activate End Try End If

 

The main reason this code could fail is either the view and pos rep are not named the same or the iLogic trigger is not firing. If each pos rep has a parameter changed between them the "Any Model Parameter Change" trigger should work perfectly.

 

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
Message 5 of 14

k14348
Advocate
Advocate

Hi,

  Actually i have 5 Nos. of view Rep. and 5 Nos. of Positional Rep. Details are as follows:-

 

View Rep:-

Stub 600

Stub 500

Stub 400

Stub 300

Stub 200

Stub 100

 

Positional  Rep:-

Stub 600

Stub 500

Stub 400

Stub 300

Stub 200

Stub 100

 

If i double click (that means activate) Stub 600 of View Rep After run the rule manually Positional Rep Stub 600 Should be activated. If i double click Stub 500 after run the rule manually Stub 500 Positional rep Should be activated.

 

-karthikeyan M

0 Likes
Message 6 of 14

pball
Mentor
Mentor
Accepted solution

My code above works when you active a position rep and then the code will change the view rep to match. I have it setup in that order because there is not an iLogic trigger that runs when view reps are changed.

 

It would be possible to change the code so it will change the position rep to match the active view rep, but you would have to manually run the code every time.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
Message 7 of 14

k14348
Advocate
Advocate

Hi,

  I know some  vba basic and i written 4 or 5 macros. But i dont know how to learn ilogic. Can u give some guidance how to start?

 

-karthikeyan

0 Likes
Message 8 of 14

MechMachineMan
Advisor
Advisor

iLogic is just vb.net using the inventor API, as well as some built in shortcuts.

 

You can do anything iLogic does simply by using vb.net to access the inventor API.


--------------------------------------
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
0 Likes
Message 9 of 14

Anonymous
Not applicable

Dear pball z,

This code is exactly what I have been looking for. I just tested it and it works perfectly. If I was a bit more experienced with iLogic I would make the view rep the key rather than the positional rep.

 

I have an assembly with 14 stations. Each station is a sub-assembly with position reps for 18 product variants. The ability to switch smoothly between pos reps and the corresponding view in the top level is very valuable. I have voted to have this functionality built it. For now this is great! 

Thank you,

0 Likes
Message 10 of 14

Harry.Braywood
Observer
Observer

Hi,

I'm new to this, so forgive me if I'm missing something obvious.

I've tried this rule

oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item(oAsmCompDef.RepresentationsManager.ActivePositionalRepresentation.Name).activate

as stated.

And I've made sure that the view names are exactly the same as the positional representation names, characters spaces and all. My assembly file name is "14323".

But I keep getting a box saying "Error on Line 1 : 'oAsmCompDef' is not declared. It may be inaccessible due to its protection level"

How do I solve this?

0 Likes
Message 11 of 14

pball
Mentor
Mentor

Are you using all of the code posted above or just that line? That line by itself will not work, it requires the first two lines of code which define oAsmCompDef.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 12 of 14

Harry.Braywood
Observer
Observer

Thanks for the reply. It was something quite obvious (like I said, I'm totally new).

I've put the whole rule in now, and it's gone through with no errors.

However it doesn't seem to be working as I want it to.

I've got 16 views with names, and 16 representations with matching names for the relevant view.

For example, I've got one view called "Discharge Right, Suction Right". But when I double click on this view, the positional representation does not change to "Discharge Right, Suction Right"

Would you know why this is?

0 Likes
Message 13 of 14

pball
Mentor
Mentor

There are two things about this script. First you need to setup an iLogic trigger on any parameter change to run this rule. Secondly it only works when changing the positional representation and not the view rep. I am not aware of a method of triggering an iLogic script when the view rep is changed.

Check out my style edits for the Autodesk forums
pball's Autodesk Forum Style
0 Likes
Message 14 of 14

Harry.Braywood
Observer
Observer

Ah, I see.

Thanks for your help and information for this. I'll spend some time familiarising myself.

0 Likes