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 drawing population using presentation views

9 REPLIES 9
Reply
Message 1 of 10
adam
1021 Views, 9 Replies

iLogic drawing population using presentation views

I'm very new to both iLogic and programming. I've poked around a little and made simple rules to manipulate iproperties, save filetypes, change drawing borders etc. but am now looking for a bit more and am struggling (i.e. completely lost.)
I want to automate the creation of an assembly drawing from an existing presentation file. Here is the basic break-down:

Assumed Pre-Requisites:
- Using Inventor 2011
- Presentation(*.ipn) file is present and saved in same directory
- Each presentation VIEW is numbered and named (e.g. "1 - PCB Installation", "2 - Battery Insertion", etc.)

iLogic/VBA Code should:
- Select presentation file (either auto or allow user browse/select)
- Create a page in the drawing (*.idw) for each VIEW from the presentation file
- Create a base view on each page for each presentation VIEW (in numbered order)
- Each base view orientation will be derived from Saved Camera
- Each drawing page will be named using the name from the corresponding presentation VIEW name
- Each page will have a prompted entry in the Title Block that will be defaulted to the presentation VIEW name

If anyone can give me a few pointers on how to help accomplish this, I'd really appreciate it. I can't find anything in the iLogic menus, help, forums etc. deal at all with presentation files/views/cameras.
Thanks!

9 REPLIES 9
Message 2 of 10
adam.nagy
in reply to: adam

Hi,

 

I wrote this in VBA but should be possible to convert it to iLogic code:

Sub CreateViewsFromPresentationDocument()
    Dim dwg As DrawingDocument
    Set dwg = ThisApplication.ActiveDocument

    Dim pres As PresentationDocument
    Set pres = ThisApplication.Documents.Open("C:\Users\Administrator\Documents\Inventor\MyProject\chains.ipn")
    
    Dim p As AssemblyDocument
    Set p = pres.ReferencedDocuments(1)
    
    Dim v As PresentationExplodedView
    For Each v In pres.PresentationExplodedViews
        v.Activate
        
        Dim cam As Camera
        Set cam = pres.Views(1).Camera
        
        Dim s As Sheet
        Set s = dwg.Sheets.Add()
        s.Name = v.Name
        
        Dim pt As Point2d
        Set pt = ThisApplication.TransientGeometry.CreatePoint2d()
        
        Dim dv As DrawingView
        Set dv = s.DrawingViews.AddBaseView( _
          p, pt, 1, kArbitraryViewOrientation, _
          kHiddenLineDrawingViewStyle, , cam)
    Next
    
    pres.Close True
End Sub

I hope this helps.

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 10
adam
in reply to: adam.nagy

Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument
	
Dim oPresentationDoc As PresentationDocument
Dim oFileDlg As inventor.FileDialog = Nothing
InventorVb.Application.CreateFileDialog(oFileDlg)
oFileDlg.InitialDirectory = oOrigRefName
oFileDlg.CancelError = True
On Error Resume Next
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
	Return
	ElseIf oFileDlg.FileName <> "" Then 
	selectedfile = oFileDlg.FileName
End If
oPresentationDoc = ThisApplication.Documents.Open(selectedfile, False)

Dim oPresView As PresentationExplodedView
For Each oPresView In oPresentationDoc.PresentationExplodedViews
  oPresView.Activate
        
  Dim oCamera As Camera
  oCamera = oPresentationDoc.Views(1).Camera
        
  Dim oSheet As Sheet
  oSheet = oDrawingDoc.Sheets.Add()
  oSheet.Name = oPresView.Name
  ActiveSheet.SetTitleBlock("STD_Assembly_Block", oPresView.Name)
  ActiveSheet.ChangeSize("A", MoveBorderItems := True)

  Dim oPoint As Point2d
  oPoint = ThisApplication.TransientGeometry.CreatePoint2d(17.5,12.5)
        
  Dim oDrawingView As DrawingView
  oDrawingView = oSheet.DrawingViews.AddBaseView(oPresentationDoc,
   _oPoint,0.75,ViewOrientationTypeEnum.kArbitraryViewOrientation,
   _DrawingViewStyleEnum.kHiddenLineDrawingViewStyle,
   _"BaseView",oCamera)
Next

 Whoa, I had pretty much given up on this and hadn't looked at this in while.  Thanks for you response!!  Armed with your code I went in and gave this another try.  My problem now is that, while all the sheet creation happens and names get produced, the views are NOT getting produced.  The annoying part is that it isn't throwing an error... it's just not happening.  I've tried "Front" views to take the camera aspect out of the equation.  I've run another simplified version of the attached code on a Part file, just to make sure that the syntax of the AddBaseView is right, and that works fine.  BUT it won't seem to work with the Presentation Doc views.  Any clue why this wouldn't be working?

Message 4 of 10
wood.isbell
in reply to: adam

Comment out "On Error Resume Next" and see what you get. I don't see anything wrong with your code. Have you zoomed out to make sure it is not placing the views out of bounds? I like to specify location based on a percentage of the sheet size:

 

oPoint.x = oSheet.Width * 0.4375
oPoint.y = oSheet.Height * 0.5625

 

 Use something like that after defining oPoint, if that is an issue.

 

Message 5 of 10
adam
in reply to: wood.isbell

Thanks wisbell.

I was under the impression that it only applied to the portion of the code relating to the file selection dialog.  Is that not a correct assumption?

Without the "On Error Resume Next" I get the following error.  Unfortunatley it is gibberish to me 😞 

 

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.DrawingViews.AddBaseView(_Document Model, Point2d Position, Double Scale, ViewOrientationTypeEnum ViewOrientation, DrawingViewStyleEnum ViewStyle, String ModelViewName, Object ArbitraryCamera, Object AdditionalOptions)
at LmiRuleScript.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

The insertion point is currently hard-coded as I was trying to minimize places for this to wrong.  The values placed a view nicely on the page when I ran my simplified code with a *.ipt file.  I am sure that there is no view being placed, as none is visible in the model browser.

 

Message 6 of 10
wood.isbell
in reply to: adam

"On Error" will work on everything below it unless you tell it otherwise.

 

In Adam Nagy's code, he closed out the presentation document at the end, which is a good idea. That error is definitely occuring when it is trying to place the view, and probably because something about the referenced document is confused, but I don't know why. Try and put the "On Error" part back in as well as closing the document at the end of your code, then run it twice. The first time might close the referenced document for you or you may need to restart Inventor to get it cleared. If it doesn't work with the close code inserted after you have restarted Inventor, I am out of ideas.

 

You may make sure the usage of AddBaseView is the same in 2011. I use 2014, but I imagine it would be the same.

Message 7 of 10
adam
in reply to: wood.isbell

Good to know about the OnError stuff... thanks.

 

Unfortunately it doesn't seem like closing the file has any effect, thought it does sound like good practice.

 

Thanks for your help wisbell, but I think that I may to have to put this to rest for a while before I throw away any more time playing with it 😞

(btw. I have upgraded to 2015)

 

I feel like there is maybe something very specific to the AddBaseView command with respect to Presentation files that I'm missing.

 

Message 8 of 10
wood.isbell
in reply to: adam

Not a problem. You are probably correct about it being a specifically Presentation problem. At least in 2014, Presentations have very little support for iLogic, and I have not gotten anything to work without building it in VBA. That said, VBA is very nice for that sort of thing, and Andy was already nice enough to give you the code for a macro. You could throw that in your Application Project to try it out. It might just work.

Message 9 of 10
adam.nagy
in reply to: adam

Hi Adam,

 

In AddBaseView() I passed in the AssemblyDocument referenced by the PresentationDocument as first parameter, not the PresentationDocument itself. 🙂

So your code should be:

oDrawingView = oSheet.DrawingViews.AddBaseView(oPresentationDoc.ReferencedDocuments(1),
   oPoint, 0.75, ViewOrientationTypeEnum.kArbitraryViewOrientation,
   DrawingViewStyleEnum.kHiddenLineDrawingViewStyle,
   "BaseView", oCamera)

Note: not sure how robust it is to simply take the first referenced document, since your presentation document might reference other things too. I only used it as a proof of concept. If you know that it only references the part document or assembly document it shows then it's fine as is. 

 

Btw, you do not need underscore character in VB.NET code when passing in a function's parameters on separate lines.

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 10 of 10
adam
in reply to: adam.nagy

Thanks Adam,

I did notice that, but that doesn't seem to get the desired result.  I think maybe I didn't do a good job explaining what it was I was trying to accomplish.

Neglecting (for now) the saved camera part, which doesn't seem to work, and using kFrontVewOrientation... The result of that code is each drawing sheet all having a base view of the same *.iam file.  What I'm looking for is for each sheet to have a base view of the corresponding presentation exploded view (for which the sheet has been named).  Does this make sense?

 

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

Post to forums  

Autodesk Design & Make Report