iLogic ruel that exports in .dwg

iLogic ruel that exports in .dwg

Anonymous
Not applicable
1,523 Views
6 Replies
Message 1 of 7

iLogic ruel that exports in .dwg

Anonymous
Not applicable

Hello. i have created an iLogic in side of an assembly that from the input of height, length and width changes the dimensions of a product and calculates the size of some parts. I want to add a function that would export the part drawings in .dwg. If any one has code that those this i would highly appreciate it.

 

I understand that i need to make a For Each rule to achieve that, but i'm not very experienced and found myself at road block in declaring the variables, i've searched but the only things that i found are very technical and sound like gibberish to me, i understand the concept of variables but i'm finding trouble knowing witch and when to use them, if any one could redirect me to something that explains it step by step it would be awesome.

 

I've attached the assembly im working one if needed.

 

thanks in advance

 

 

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

JelteDeJong
Mentor
Mentor

you did not specify how you wanted to export the dwg files. So I assume you need pdf files. try this:

Dim doc As AssemblyDocument = ThisDoc.Document
For Each refDoc As Document In doc.AllReferencedDocuments

    Dim fileName As String = refDoc.FullFileName
    Dim ext As String = IO.Path.GetExtension(fileName)
    Dim dwgFileName As String = fileName.Replace(ext, ".dwg")
    Dim pdfFileName As String = fileName.Replace(ext, ".pdf")

    Dim dwgDoc As DrawingDocument = ThisApplication.Documents.Open(dwgFileName)
    dwgDoc.SaveAs(pdfFileName, True)
    dwgDoc.Close(True)
Next

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 7

Anonymous
Not applicable

Hi thanks for the reply

 

I wanted it to export the associated drawings in .dwg (file > export > .dwg) when you do this it gives you a "different" type of dwg

 

when i tried to run it with a subassembly inside it gives me a error, is it possible to make it go into all subassemblies and do the same thing?

 

0 Likes
Message 4 of 7

JelteDeJong
Mentor
Mentor
Accepted solution

I didn't understand that you wanted to create Autocad Dwg file. These are a bit more difficult to make. for that to work you need to save a DWGOut.ini file (= configuration file). You can just save the settings you use when you create an Autocad Dwg manually.

JelteDeJong_0-1635084208772.png

the rule expects that you save that file on "C:\temp\DWGOut.ini" but you can save it anywhere but then you need to change the location in the rule. (see comments in the rule.)

 

This script will go into all files referenced by the assembly (also sub-assembly parts).  but for the script to work the dwg file name and part/assembly file name must be the same.

 

Sub Main()

    Dim doc As AssemblyDocument = ThisDoc.Document
    For Each refDoc As Document In doc.AllReferencedDocuments

        Dim fileName As String = refDoc.FullFileName
        Dim ext As String = IO.Path.GetExtension(fileName)
        Dim inventorDwgFileName As String = fileName.Replace(ext, ".dwg")
        Dim autocadDwgFileName As String = fileName.Replace(ext, "-acad.dwg")

        If (IO.File.Exists(inventorDwgFileName) = False) Then
            MsgBox("Could not find inventor dwg: " & inventorDwgFileName)
            Continue For
        End If

        Dim dwgDoc As DrawingDocument = ThisApplication.Documents.Open(inventorDwgFileName)
        DWGOutUsingTranslatorAddIn(dwgDoc, autocadDwgFileName)
        dwgDoc.Close(True)
    Next

End Sub
Public Sub DWGOutUsingTranslatorAddIn(doc As DrawingDocument, newFileName As String)

    ' Set the path to your DWGOut.ini fiile here
    Dim dwgOutIniFile As String = "C:\temp\DWGOut.ini"

    Dim oDWGAddIn As TranslatorAddIn = Nothing
    Dim i As Long

    For i = 1 To ThisApplication.ApplicationAddIns.Count
        If ThisApplication.ApplicationAddIns.Item(i).ClassIdString = "{C24E3AC2-122E-11D5-8E91-0010B541CD80}" Then
            oDWGAddIn = ThisApplication.ApplicationAddIns.Item(i)
            Exit For
        End If
    Next

    If oDWGAddIn Is Nothing Then
        MsgBox("DWG add-in not found.")
        Exit Sub
    End If

    If (IO.File.Exists(dwgOutIniFile) = False) Then
        MsgBox("Unable to find: " & dwgOutIniFile)
        Exit Sub
    End If

    If Not oDWGAddIn.Activated Then
        oDWGAddIn.Activate()
    End If

    Dim oNameValueMap As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
    oNameValueMap.Add("Export_Acad_IniFile", dwgOutIniFile)

    Dim oContext As TranslationContext = ThisApplication.TransientObjects.CreateTranslationContext()
    oContext.Type = IOMechanismEnum.kFileBrowseIOMechanism

    Dim oOutputFile As DataMedium = ThisApplication.TransientObjects.CreateDataMedium()
    oOutputFile.FileName = newFileName
    Call oDWGAddIn.SaveCopyAs(doc, oContext, oNameValueMap, oOutputFile)

End Sub

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 5 of 7

Anonymous
Not applicable

sorry if i am being picky 

 

but i have some rules in the drawings that define the scale and there not being implemented, i tried using the trigger event but its not working,

 

Another thing can they be exported with the part number as there name.

 

thank you

0 Likes
Message 6 of 7

Anonymous
Not applicable

i tryed replacing it like this but had no success ...

 

        Dim fileName As String = refDoc.FullFileName
        Dim ext As String = IO.Path.GetExtension(fileName)
        Dim inventorDwgFileName As String = fileName.Replace(ext, ".dwg")
        Dim autocadDwgFileName As String =fileName.Replace(ThisDoc.Path & iProperties.Value("Project", "Part Number"), ".dwg")

 

0 Likes
Message 7 of 7

A.Acheson
Mentor
Mentor

 

The ilogic snippet on it's own will reference only the main assembly rule. 

iProperties.Value("Project", "Part Number")

 You will need to reference each document  in the for loop of documents.

iProperties.Value(refDoc.DisplayName,"Project", "Part Number")

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan