Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

prompt that allows document editing before continuing

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
bsnyderACLUW
594 Views, 5 Replies

prompt that allows document editing before continuing

Hi everyone,

 

I have done a bit of looking but didn't find any information on this. What I am wanting to do is have my Ilogic code run through several drawings checking for proper number of views. What I want is to be prompted when a drawing does not have enough views. I want to use this stopping point to edit the drawing, then select ok to continue running the code for the rest of the documents. I don't know if this is possible with Ilogic. Any help would be appreciated.

 

Inventor 2019

Thank you,

5 REPLIES 5
Message 2 of 6

Hi,

Break execution of iLogic rule, edit document manually and continue execution is little bit tricky. You can use some another approach.

1) You can run your iLogic and when the number of drawing views is not correct, write the file name to external file. Then you can open and edit this drawings manually.

2) You can store your iteration variable (for example "lastIndex") and file name collection to shared variables and iterate this collection with For loop. In For loop you can store last iteration variable value to shared variable lastIndex. When you found drawing with incorrect vies cout, keep open the drawing and break execution. When you finish manual edits, start execution again and start iteration from lastIndex

3) You can create external application and in this case is possible to have continue button and it can work as you write above. This is because Inventor and your application runs in separate processes.

 

Code sample for approach 2)

 

 

Sub Main
	Dim drawingsPath As String = "C:\Path\To\Your\Drawings\Here"
	Dim drawingsSharedVariableName = "drawingFileNames"
	Dim lastIndexSharedVariableName = "lastIndex"

	Dim drawingFileNames As String()
	If SharedVariable.Exists(drawingsSharedVariableName)
		drawingFileNames = SharedVariable(drawingsSharedVariableName)
	Else
		drawingFileNames = System.IO.Directory.GetFiles(drawingsPath, "*.idw", System.IO.SearchOption.AllDirectories)
		SharedVariable(drawingsSharedVariableName) = drawingFileNames
	End If

	Dim fromIndex As Integer = 0
	If SharedVariable.Exists(lastIndexSharedVariableName) Then
		fromIndex = SharedVariable(lastIndexSharedVariableName)
	End If

	For i As Integer = fromIndex To drawingFileNames.Length - 1
		Dim drawingFileName As String = drawingFileNames(i)
		If UserEditNeeded(drawingFileName) Then
			SharedVariable(lastIndexSharedVariableName) = i
			Exit Sub
		End If
	Next
	MsgBox("Done", MsgBoxStyle.Information)
	SharedVariable.RemoveAll()
End Sub

Function UserEditNeeded(drawingFileName As String) As Boolean
	Dim drawingDoc As DrawingDocument = ThisApplication.Documents.Open(drawingFileName)

	'Implement your condition here
	If drawingDoc.Sheets(1).DrawingViews.Count < 1 Then
		MsgBox("Manual edit needed", MsgBoxStyle.Exclamation)
		Return True
	Else
		drawingDoc.Close
		Return False
	End If
End Function

 

 

Message 3 of 6
Anonymous
in reply to: bsnyderACLUW

@bsnyderACLUW  Try this.

oCount is the number of views that should be in the drawing.

If the number Of Views Is more than Or less than the oCount, it will leave the the drawing open For editing.

 

 

 

Sub Main()
	Dim oFileDlg As Inventor.FileDialog = Nothing
	ThisApplication.CreateFileDialog(oFileDlg)
	oFileDlg.Filter = "Autodesk Inventor Drawings (*.idw)|*.idw"
	oFileDlg.DialogTitle = "Select Drawings To Check"
	oFileDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
	oFileDlg.MultiSelectEnabled =True 
	oFileDlg.FilterIndex = 1
	oFileDlg.CancelError = True
	On Error Resume Next
	oFileDlg.ShowOpen()
	Dim oDrgDoc As DrawingDocument
	If Err.Number <> 0 Then
		MsgBox("File not chosen.",,"Dialog Cancellation")
	ElseIf oFileDlg.FileName <> "" Then
		For Each oFileName As String In oFileDlg.FileName.Split("|")
			oDrgDoc = ThisApplication.Documents.Open(oFileName)
			
			oCount = 0
'			Loop through all drawing views
			For Each oView In oDrgDoc.ActiveSheet.DrawingViews
				oCount = oCount + 1
			Next

		
			'MsgBox(oCount)
			
			'oCount is the number of views that should be in the drawing. 
			'If the number Of Views Is more than Or less than the oCount, 
			'it will leave the the drawing open For editing.
			If oCount = 1  Then  
				oDrgDoc.Close(True)
				oDrgDoc.ReleaseReference
			End If

		Next
	End If
End Sub

 

 

 

Message 4 of 6
bsnyderACLUW
in reply to: Anonymous

@Anonymous @Michael.Navara 

 

Thank you guys for the information I will be trying these out to see which one I like better. 

 

@Michael.Navara 

You said it gets tricky doing what I ultimately want to do, do you believe this can be done?

If so do you know how? I want to make more programs that can do this. The end result will be a rule that can run several other rules on these drawings and prompt when a problem is found that can be corrected before moving on. 

 

Than you guys,

Message 5 of 6

Hi,

I believe this can be done, and I know, how to do this. (This is my job 😉).

At first you need to know how to write external exe application with communication to Inventor. Some resources are in Inventor SDK. This can't be done in iLogic, you must use full Inventor API and another IDE (for example Visual Studio Community Edition).

 

Then prepare your business logic with checks and repair procedures. Finally combine this to one application with (awesome 😀 )UI.

 

Some resources here:

http://help.autodesk.com/view/INVNTOR/2020/ENU/?guid=GUID-6FD7AA08-1E43-43FC-971B-5F20E56C8846

 

Message 6 of 6

Here is very simple example, how to write this as console application. In this example is minimal error checking for clarity.

Application is written in C# (VS2019). Source code and compiled application is in attachment.

 

Main code in Program.cs

 

using Inventor;
using System;
using System.IO;
using System.Runtime.InteropServices;
using Environment = System.Environment;

namespace SimpleDrawingCheckApp
{
    class Program
    {
        private static Application inventor;
        static void Main(string[] args)
        {
            //First command line argument must be path to your drawings.
            //For example: "C:\Path\To\Your\Drawings\Here";
            //Check project Properties->Debug for test data
            string drawingsPath = GetDrawingsPath(args);

            if (drawingsPath == null)
            {
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
                return;
            }

            inventor = (Application)Marshal.GetActiveObject("Inventor.Application") as Application;

            if (inventor == null)
            {
                Console.WriteLine("Start Inventor application first.");
                Console.ReadKey();
                return;
            }


            var drawingFileNames =
                Directory.GetFiles(drawingsPath, "*.idw", SearchOption.AllDirectories);

            foreach (string drawingFileName in drawingFileNames)
            {
                //Skip files in OldVersions directories
                if (drawingFileName.Contains("OldVersions"))
                    continue;

                var drawing = inventor.Documents.Open(drawingFileName) as DrawingDocument;
                if (drawing == null)
                    continue;

                Console.Write($"Checking {drawing.DisplayName}");
                if (UserEditNeeded(drawing))
                {
                    Console.WriteLine($"Edit and save document: {drawing.DisplayName}");
                    Console.WriteLine($"Press any key to continue...");
                    Console.ReadKey();
                    Console.WriteLine(new string('-', 10));
                }

                drawing.Close();
            }

            Console.WriteLine("DONE\r\nPress any key to exit...");
            Console.ReadKey();

        }

        private static string GetDrawingsPath(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Path to the drawings drectory not specified");
                return null;
            }

            string path = args[0];
            path = Environment.ExpandEnvironmentVariables(path);

            if (Directory.Exists(path) == false)
            {
                Console.WriteLine($"Directory not exists: {path}");
                return null;
            }

            return path;
        }

        private static bool UserEditNeeded(DrawingDocument drawing)
        {
            //Implement your condition here
            if (drawing.Sheets[1].DrawingViews.Count < 1)
            {
                Console.WriteLine();
                Console.WriteLine(new string('-', 10));
                Console.WriteLine("Drawing view is missing");
                return true;
            }

            //Document is OK
            Console.WriteLine(" - OK");
            return false;
        }
    }
}

 

 

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

Post to forums  

Autodesk Design & Make Report