Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Ilogic save problem

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
NicholasProvo
566 Views, 7 Replies

Ilogic save problem

Hey all, I created an Ilogic rule that creates a drawing out of the current assembly, it opens a template drawing and places views. The problem is I can't get the drawing to be saved. It says that the document is not a drawing, I think it's referening to the assembly. Any ideas to save the new created drawing in the same directory and name as the assembly? Here is the code I'am using:

 

 

 

    Dim oFileManager As FileManager
     oFileManager = ThisApplication.FileManager
    'create drawing document
    Dim oNewDoc As DrawingDocument
    Dim FilePath As String
    Dim oSheet As Sheet
    
    
Dim oPartDoc as Document
Dim oView1 as DrawingView
Dim oView2 as DrawingView
Dim oView3 as DrawingView
Dim oView4 as DrawingView
Dim oView5 as DrawingView
Dim oDrawingDoc as DrawingDocument
Dim oPartsList As PartsList
Dim x As Integer
Dim y As Integer
x=5    
y=15    
    

'Creat main Assembly drawing
    oNewDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, "V:\Inventor\Templates\Glacio Automatic Draw.idw", True)
    Dim oActiveSheet As Sheet
      oActiveSheet = oNewDoc.ActiveSheet
       ' Open the sheet metal document invisibly
       

       
    Dim oModel As Document
          oModel = ThisApplication.Documents.Open(ThisDoc.PathAndFileName(False) & ".iam", False)
          ViewScale = 1/5
        'load the part that you want to create a view from
        'oModel = ThisApplication.Documents.Open(ThisDoc.PathAndFileName, False)
        'Create points on the drawning where the views must be created
        oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(x, y) ' front view
        oPoint2 = ThisApplication.TransientGeometry.CreatePoint2d(x, 5) ' top view
        oPoint3 = ThisApplication.TransientGeometry.CreatePoint2d(15, y)' right view
        oPoint4 = ThisApplication.TransientGeometry.CreatePoint2d(25, y)' ISO View (or current view)
        oPoint5 = ThisApplication.TransientGeometry.CreatePoint2d(28, 6) 'Part list
        
        'Creates the views and part list
        oBaseView = oActiveSheet.DrawingViews.AddBaseView(OModel,oPoint1, ViewScale ,ViewOrientationTypeEnum.kDefaultViewOrientation, DrawingViewStyleEnum .kHiddenLineRemovedDrawingViewStyle, "My View")
        oActiveSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, Inventor.DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, ViewScale)
        oActiveSheet.DrawingViews.AddProjectedView(oBaseView, oPoint3, Inventor.DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, ViewScale)
        oActiveSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, Inventor.DrawingViewStyleEnum.kHiddenLineDrawingViewStyle, ViewScale)
        oActiveSheet.DrawingViews.AddBaseView(OModel,oPoint4, ViewScale ,ViewOrientationTypeEnum.kCurrentViewOrientation, DrawingViewStyleEnum .kShadedDrawingViewStyle)
      'ThisDrawing.ResourceFileName = "V:\Inventor\Templates\Glacio\Glacio.idw"

ThisDrawing.Document.SaveAs(ThisDoc.ChangeExtension(".idw"),True)

 

 

 

 

 

7 REPLIES 7
Message 2 of 8

I forgot to add some pictures to clear things out 😄

Message 3 of 8
MegaJerk
in reply to: NicholasProvo

If you’re saving a document for the first time using SaveAs, you should set the second argument to False. This is detailed here : http://modthemachine.typepad.com/my_weblog/2013/02/

 

 

So you could do something like : 

 

Call oNewDoc.SaveAs(filePath, False) 

 



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 4 of 8
NicholasProvo
in reply to: MegaJerk

Indeed! It worked out using this line eventually:

 

oNewDoc.SaveAs(ThisDoc.PathAndFileName(False) & ".idw", True)

 

Thank you!

Message 5 of 8
MegaJerk
in reply to: NicholasProvo

you're welcome! 

Also, becuase I also used to be in the habit of doing what you did, I wanted to point out that the line : 

 oModel = ThisApplication.Documents.Open(ThisDoc.PathAndFileName(False) & ".iam", False)

 

is redundant assuming that you are running this code from an Assembly that is already open. If that's the case you could simply change the structure a bit by doing something like : 

Dim oModel As Document 
oModel = ThisApplication.ActiveDocument 

'now all of the stuff to create your drawing. 

 
It's not a huge problem, the way that you're already doing it, but it may save you from writing out lines like this in the future and save you .000000000000000005 seconds 😉 

Glad to hear that everything worked! 




If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 6 of 8
NicholasProvo
in reply to: MegaJerk

Haha well it definetly saves me that 0.0005 second 😄 I just started with ILogic a week ago, I'm starting to get the hang out of it. And it's a great tip also, now I understand how the logic of iLogic programming works (I made a stupid joke there 😛 ) anyway I have only one part I can't get out with.

 

I placed a parts list on the drawing with this line:

 

oPartsList = oActiveSheet.PartsLists.Add(oBaseView, oPoint5)

 

Now how do I make a parts list with a BOM view set to "Parts Only"? Cause if you enter that line there will show up a parts list but the BOM view is set to "Structered"? Any last idea on that, I think it should be such an obvious answer cause I can't find the answer anywhere on the internet. So here my public apologie if it's a stupid question 😉

 

Cheers

Message 7 of 8
MegaJerk
in reply to: NicholasProvo

Awesome hotdogs! 

As for your partslist problem, I'm going to assume that oPartsList equals the actual parts list that you create when you run that code meaning that this : 

oPartsList.Level = PartsListLevelEnum.kPartsOnly

 

I believe that should work, but if it doesn't hit me up. 

In the meantime I highly recommend taking the time to look at your Inventor install folder for either a Local Help, Help Lite, or some other form of Help folder. Inside of it should be a file named something like 'admapi_##_0.chm", the '##' being different for each version of Inventor. That is the Api help file and contains references and documentation to nearly every little part of the Inventor API! you can use it to look up properties of the objects that you're messing with to get a good understanding of how they work and how you can rope them into doing the things that you want them to do. And, while it doesn't contain examples for everything, it certainly does a good job of giving your some sort of idea on how to get the most out of the software. 

If you find that you do not have a help folder in your Inventor directory, you may need to install it! You can find the downloads for those install files here : Autodesk Inventor Downloads Station

You may have already known all of this, but even so, as you get more comfortable using iLogic and the API, it will become your number one source of ultimate power... Well, that and the rudimentary but powerful VBA debugger.

Enjoy!



If my solution worked or helped you out, please don't forget to hit the kudos button 🙂
iLogicCode Injector: goo.gl/uTT1IB

GitHub
Message 8 of 8
NicholasProvo
in reply to: MegaJerk

Thanks MegaJerk I'm using the help now (had to download it) and I'm starting to create powerfull macro's that reduces the time of placing views and dimensions. Saving alot of time for me! Also great on the partslist, works b-e-a-u-t-i-f-u-l-l-y!!

 

Thanks!

 

Greetz

 

Provo

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

Post to forums  

Autodesk Design & Make Report