SaveAs from Unsaved IDW to DXF

SaveAs from Unsaved IDW to DXF

cadman777
Advisor Advisor
3,558 Views
23 Replies
Message 1 of 24

SaveAs from Unsaved IDW to DXF

cadman777
Advisor
Advisor

Hey Guys,

 

Is there a way to use iLogic to save a DXF from an IDW that never was saved?

 

Reason I ask is b/c I want to create a separate IDW of each flatpattern part in an assembly, and then save it to a DXF file using SaveAs w/options, then close the IDW after making the DXF file. But I don't know IF that kind of operation can be done on an unsaved IDW.

 

Any help is appreciated.

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Accepted solutions (1)
3,559 Views
23 Replies
Replies (23)
Message 2 of 24

Michael.Navara
Advisor
Advisor

It is possible. But you need to specify output full file name and you can't use existing file name as source. Because it is empty.

0 Likes
Message 3 of 24

WCrihfield
Mentor
Mentor

If your main concern is that you don't want to leave those drawing files behind, because you have no other use for them, we could just go ahead and save those drawings somewhere temporarily, then export the DXF, then delete the drawing file again afterwards, to clean up.  That could all be done by the code, if needed.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 24

cadman777
Advisor
Advisor

Thanx Michael.

I have tried that, but without success.

But my problem may be my understanding of the VBA code I copied from the API help.

Today I plan on giving it more thought to see if I can get it to work.

Cheers...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 5 of 24

cadman777
Advisor
Advisor

Great idea. I thought about doing it that way, but that would entail more code that I didn't want to get into. Do you know if I can do the export on an unsaved idw? I can't find any info on it anywhere. But then again, I'm not the sharpest knife in the drawer these days!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 6 of 24

Curtis_Waguespack
Consultant
Consultant

Hi @cadman777 

 

I think what you're wanting to do is get the part model name from the drawing. See this example.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

oPath = "C:\Temp\DXFs\"
oDoc = ThisDrawing.ModelDocument.FullFileName 'gets the model from the drawing
oDocName = IO.Path.GetFileNameWithoutExtension(oDoc)
oDXFName = oPath & oDocName & ".dxf"

'standard DXF out put code
' Get the DXF translator Add-In.
Dim DXFAddIn As TranslatorAddIn
DXFAddIn = ThisApplication.ApplicationAddIns.ItemById("{C24E3AC4-122E-11D5-8E91-0010B541CD80}")
'Set a reference to the active document (the document to be published).
Dim oDocument As Document
oDocument = ThisApplication.ActiveDocument
Dim oContext As TranslationContext
oContext = ThisApplication.TransientObjects.CreateTranslationContext
oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism
' Create a NameValueMap object
Dim oOptions As NameValueMap
oOptions = ThisApplication.TransientObjects.CreateNameValueMap
' Create a DataMedium object
Dim oDataMedium As DataMedium
oDataMedium = ThisApplication.TransientObjects.CreateDataMedium
' Check whether the translator has 'SaveCopyAs' options
If DXFAddIn.HasSaveCopyAsOptions(oDocument, oContext, oOptions) Then
Dim strIniFile As String
strIniFile = "C:\temp\dxfout.ini"
' Create the name-value that specifies the ini file to use.
oOptions.Value("Export_Acad_IniFile") = ""
End If
'Set the destination file name
oDataMedium.FileName = oDXFName
'Publish document.
DXFAddIn.SaveCopyAs(oDocument, oContext, oOptions, oDataMedium)

 

 

Message 7 of 24

cadman777
Advisor
Advisor

Curtis,

 

That's the code I've been trying to use that I got from the API snippets. Your idea is exactly what I want to do. Only thing is, I tried doing it using code that assembles the filename from iProperties about 3 subs prior to when I want it done in the iLogic rule. So today after 3 hours of fruitless 'hacking', I resigned myself to doing what you just said. So you just saved me the trouble of hunting down the code to use. I'll just add some of your beginning code and change it a bit to get the filename custom iproperty I inserted into each file.

 

Incidentally, in the process of my 'hacking', I tested the code to find out IF I can DXF out an unsaved IDW, which succeeded. So at least I now know I can do that once I get that filename out of the part.

 

Thanx for helping!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 8 of 24

TechInventor20
Advocate
Advocate

It is not that hard.

 

dim FilePathdwg as string = "C:\-your location-\
dim Savename as string = "-Name of file-\
dim Extension as string = ".dxf"
ThisDoc
.Document.SaveAs(FilePathdwg & Savename & Extension , False)
0 Likes
Message 9 of 24

cadman777
Advisor
Advisor

Thanx Tech.

But your code only works if the idw file is saved.

These aren't.

What I'm working on is getting the drawing name from the part file without having to acces the part from the idw.

But that looks like the only option at this point, just like Curtis shows at the top of his rule.

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 10 of 24

TechInventor20
Advocate
Advocate

then try this? I dont know what it adds but I use it in my automatic drawing save rule.

 

dim FilePathdwg as string = "C:\-your location-\
dim Savename as string = "-Name of file-\
dim Extension as string = ".dxf"
dwgtype = rulearguments("dwgtype")

ThisDoc
.Document.SaveAs(FilePathdwg & dwgtype & Savename & Extension , False)

  

0 Likes
Message 11 of 24

cadman777
Advisor
Advisor

This is the line that is in question:

dim FilePathdwg as string = "C:\-your location-\

My rule gets the path from the open iam file.

It's a bit more complex than that, I believe.

 

This is the part of Curtis' rule that I'm going to use when I work on it today:

oDoc = ThisDrawing.ModelDocument.FullFileName 'gets the model from the drawing
oDocName = IO.Path.GetFileNameWithoutExtension(oDoc)
oDXFName = oPath & oDocName & ".dxf"

I can do it one of 2 ways:

1. Get the path from the part file, or

2. Pull the full filename from the part file (I pushed that info into the part file under a Custom iProperty)

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 12 of 24

cadman777
Advisor
Advisor

Hey Curtis,

Can you show me something?

Where did you find this in the ObjectModel?

oDoc = ThisDrawing.ModelDocument.FullFileName 'gets the model from the drawing

How do I know that I can access the ModelDocument from the Drawing document?

Where do I learn that?

Then can you tell me how to access the Custom iProperties from 'oDoc'?

Or at least link me to info that directly explains it.

Thanx...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 13 of 24

Curtis_Waguespack
Consultant
Consultant

Hi @cadman777 

 

I pulled that from the iLogic snippets as shown in this screen grab below... that snippet gets the first model reference that is finds in the drawing.

 

note that your version might not include all of these snippets, as some of these were added later .

 

As for getting the iProperties, something like this should work:

oDoc = ThisDrawing.ModelDocument.FullFileName 
oDocName = IO.Path.GetFileName(oDoc) 
oDesc = iProperties.Value(oDocName, "Project", "Description")

MsgBox(oDesc,,"iLogic")

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

Curtis_W_0-1638992184939.png

 

Message 14 of 24

WCrihfield
Mentor
Mentor

Hi @cadman777.  Just an additional note about that ThisDrawing.ModelDocument thing.  Some objects and methods are in the main API area...

WCrihfield_0-1638993241331.png

...while other objects and methods are only in the iLogic only area...

WCrihfield_1-1638993346163.png

... that's part of why some stuff is complicated and hard to find.

The term/object 'ThisDrawing' is found here:  IManagedDrawing Interface (under iLogic API > Autodesk.iLogic.Interfaces > IManageddDrawing Interface)

You will see on that page that the term 'ThisDrawing' is a 'predefined' object that points to this interface.

Then when you look further down on that page, you see the links and descriptions about the Properties and Methods exposed under that object...and one if its Properties is called 'ModelDocument'.  That is where that part comes from.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 15 of 24

cadman777
Advisor
Advisor

Thank you very much!

That's the thing I'm trying to 'map out' b/c I can't memorize all this stuff anymore.

I need a MAP to follow every time I go down the iLogic/VBA rabbit-hole so I don't get lost and so I don't make illegal calls, which is what I'm constantly doing while hacking my way through this b/c I don't know where anything originates or travels to its end.

Is there anybody who has mapped all this stuff out so it's easy to find and follow?

Or is it the typical Autodesk CLUSTERF**K of data that they expect you to manage as they add greater complexity to it?

Anyway, thanx for the direction!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 16 of 24

cadman777
Advisor
Advisor

Curtis,

Your pics speak volumes!

My snippets list and code is slightly different.

No worries, the little stuff I'm getting the hang of.

I just need to find what I need when I need it.

That's the biggest SNAFU in coding this stuff.

Cheers...

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 17 of 24

cadman777
Advisor
Advisor

OK Curtis,

With a little massaging I got rid of all by one error that prevents the rule from accessing the part-embedded iProperty:

"The document....was not found."

The MessageBox shows the correct FullFileName for the model part, but for the error seems to indicate that Inventor can't see or find the file. Result: Inventor can't access the iProperties.

If I hard-code the Path + FileName, the rule works.

That tells me the problem is in how the code that is trying to access the iProperties.

I tried about 10 different tings I found on the Internet and in the Customization Forum, but to no avail.

Everything revolves around accessing the part model's iProperties.

Any ideas what's up?

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 18 of 24

Curtis_Waguespack
Consultant
Consultant

Hi @cadman777 ,

 

If I understand correctly, you're using the full file name in the iProperty line, which will not work.

 

The IO.Path.GetFileName line needs to be provided the full path to extract file name, and then the iProperty line needs just the file name.  The comments in this example might better illustrate it.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

'example returns: C:\Temp\Bolt1.ipt
oDoc = ThisDrawing.ModelDocument.FullFileName 
'example returns: Bolt1.ipt
oDocName = IO.Path.GetFileName(oDoc) 
'example uses: "Bolt1.ipt" to return the description iproperty value
oDesc = iProperties.Value(oDocName, "Project", "Description")

MsgBox(oDesc,,"iLogic")

 

Message 19 of 24

cadman777
Advisor
Advisor

Hi Curtis,

 

Thanx for the tip.

The annotations help.

 

That code throws this error:

"iProperties

  The component [value of oDesc from oDocName] was not found."

Any ideas why?


Seems to me the problem is that iLogic is not able to use oDocName to find the iProperty in the part.

I just spent the last 4 hours trying to figure out why and how to fix it.

I have no clue.

 

Error message DB:

cadman777_0-1639009017448.jpeg

I have no idea what any of that doubletalk means.

 

Incidentally, I had to change this line:

oDoc = ThisDrawing.ModelDocument.FullFileName

To this:

oDoc = ThisDoc.ModelDocument.FullFileName

To get the rule to work in 2010.

Got it from the Snippets panel.

 

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 20 of 24

cadman777
Advisor
Advisor

Never mind.

I made a WORK-AROUND for it:

1. share the part iProperty with the drawing

cadman777_1-1639010535593.png

Change your code from this:

oDesc = iProperties.Value(oDocName, "Project", "Description")

To this:

oDesc = iProperties.Value("Project", "Description")

 In order to get the iProperty from the drg instead of from the model.

That's a direct copy from the iLogic shippets panel.

 

But I still want to know how to get that iProperty from the part model while inside a drawing.

Would you please show me how?

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes