Open assy from the same folder as drawing

Open assy from the same folder as drawing

tomislav.peran
Advocate Advocate
307 Views
4 Replies
Message 1 of 5

Open assy from the same folder as drawing

tomislav.peran
Advocate
Advocate

Hello, 

 

This is a code used to make a view from the assy. In a code I have to write the location of the assy.

 

Since the drawing and the assembly are in the same folder I would like to find a way not to write the exact location of the assy. I tried a few things but it did not work.

 

Dim oDrawingDoc As DrawingDocument
oDrawingDoc = ThisApplication.ActiveDocument 
      
Dim oSheet As Sheet
oSheet = oDrawingDoc.Sheets.Item(1)
       
Dim oPoint1 As Point2d
oPoint1 = ThisApplication.TransientGeometry.CreatePoint2d(5#, 5#)

Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.Documents.Open(C:\...\"My_assy.iam", False) 

Dim oView1 As DrawingView
oView1 = oSheet.DrawingViews.AddBaseView(oAssyDoc, _
    oPoint1, 1#, kBottomViewOrientation, kHiddenLineDrawingViewStyle)

Call oAssyDoc.Close(True)

 If somebody could help it would be great 🙂

 

Tom

0 Likes
Accepted solutions (1)
308 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor
Accepted solution

I noticed the character "#" in 3 places within your posted code.  Did that get automatically converted from some other character by the post?  Was that supposed to be a zero?  I removed that character from those 3 locations when I created the edited version below for you to try out, so you may need to fix those values if that's not correct.

Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument 
Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(1)
Dim oPoint1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(5, 5)
Dim oPath As String = System.IO.Path.GetDirectoryName(oDrawingDoc.FullFileName)
Dim oAssyFullFileName As String = System.IO.Path.Combine(oPath, "My_assy.iam")
Dim oAssyDoc As AssemblyDocument = ThisApplication.Documents.Open(oAssyFullFileName, False) 
Dim oView1 As DrawingView
oView1 = oSheet.DrawingViews.AddBaseView(oAssyDoc, _
    oPoint1, 1, kBottomViewOrientation, kHiddenLineDrawingViewStyle)
oAssyDoc.Close(True)

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 5

tomislav.peran
Advocate
Advocate

Hi WCrihfield,

 

Thank you a lot! I am using Inventor Programming/API help to learn more about how to create codes in Inventor. 

 

Code that I pasted is found here (only original code is used for the part and I changed it for assembly): 

 

https://help.autodesk.com/view/INVNTOR/2021/ENU/?guid=GUID-66470F9F-8563-4D53-91BE-F4769943E71C

 

There they use symbol #. They also use term "Set"  which actually I delete every time I am trying out the code. I assume that is Visual Basic thing but I have no idea. 

 

Tom 

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor

OK.  I see now.  Those are examples for use in VBA.  That's why they are using the 'Set' keyword at the beginning of a line that sets the value of a variable.  That term is not needed for that purpose in iLogic or vb.net.  And the "#" symbol can be used for directly interpreting a variable as a Double data Type.  Here is a link to a page about it in vb.net (vb.net is used by iLogic).  I just don't see it used that much in iLogic.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

tomislav.peran
Advocate
Advocate

Hi WCrihfield,

 

Thanks a lot for the explanation and for the link! Finally that is clear as well 🙂

 

Tom

0 Likes