Save option

Save option

tomislav.peran
Advocate Advocate
486 Views
6 Replies
Message 1 of 7

Save option

tomislav.peran
Advocate
Advocate

Hello,

 

I would like to save the drawing in the same location as the assembly from which it is created after it is created, but I do not seem to find a way to do it. 

 

Is that doable via code or does the user need to save the drawing manually the first time after its creation?

I do not want to use SaveAs with the written location in the code.

 

Tom

0 Likes
Accepted solutions (1)
487 Views
6 Replies
Replies (6)
Message 2 of 7

Daan_M
Collaborator
Collaborator
Accepted solution

Hi,

 

Try something like this:

Dim oDoc As AssemblyDocument = ThisDoc.Document
oPath = ThisDoc.Path

Dim oDrawingDoc As DrawingDocument
Dim oDrawingDocName As String = "testdrawing.dwg"

oTemplateLoc = "C:\Data\TestTemp.dwg"
oDrawingDoc = ThisApplication.Documents.Add(kDrawingDocumentObject, oTemplateLoc, True)

oDrawingDoc.SaveAs(oPath & "\" & oDrawingDocName, True)

oDrawingDoc.Close
Message 3 of 7

tomislav.peran
Advocate
Advocate

Hi Daan_M,

 

That should work in my opinion but It does not in my document. 

I will try later to test some more. Thanks for the help though!

 

 

 

 

0 Likes
Message 4 of 7

Daan_M
Collaborator
Collaborator

@tomislav.peran If you show the error that comes up we can look further into it. 

It works fine for me so i think it's dependant on the rest of your code.

Message 5 of 7

tomislav.peran
Advocate
Advocate

Hi Daan_M,

 

The code you placed works indeed. I have tested it in another assembly. 

 

But this is the code I have in my assy and there it does not work for some reason...I am copying only the first part. The rest of the code places views on the sheet 1 which is not that interesting here.

 

Error is general....parameter is not correct...

 

Dim oDoc As Document

oDoc = ThisApplication.ActiveDocument

oExt = Right(oDoc.FullDocumentName, 3) 'get file extension

oPath = ThisDoc.Path

Dim oDrawingDocName As String = User_parameter_1

Try 'to open the drawing 
	ThisApplication.Documents.Open _
	(ThisDoc.PathAndFileName(True).Replace(oExt, "idw"))
	Return 'exit rule
Catch	
End Try

Dim oDrawingDoc As DrawingDocument 
oDrawingDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, "C:\Inventor\template.idw", True) oDrawingDoc.SaveAs(oPath & "\" & oDrawingDocName, True) oDrawingDoc.Activate() Dim oSheet As Sheet
oSheet = oDrawingDoc.Sheets.Item(1) Dim oPoint1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(20, 20)

...

 

0 Likes
Message 6 of 7

tomislav.peran
Advocate
Advocate

Ah I have found the mistake...forgot the extension...

 

Dim oDrawingDocName As String = User_parameter_1 & ".idw"

The first mistake I did was running the code from the template that the drawing uses. That does not work.

 

You placed the code in assembly and that works. 

 

Thanks Daan for the help!

 

Tom

Message 7 of 7

brandontsche
Community Visitor
Community Visitor

G

0 Likes