GetActiveDocument

GetActiveDocument

Ruffy85
Collaborator Collaborator
1,624 Views
4 Replies
Message 1 of 5

GetActiveDocument

Ruffy85
Collaborator
Collaborator

Hello together,

 

i try to convert this ilogic to C#

 

 'catch and skip errors
On Error Resume Next
'define the active assembly
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ThisApplication.ActiveDocument 

'get user input as True or False
wfBoolean = InputRadioBox("Turn all Sketches On/Off", "On", "Off", False, "iLogic")

' Process the rule, wrapping it in a transaction so the 
' entire process can be undone with a single undo operation. 
Dim trans As Transaction 
trans = ThisApplication.TransactionManager.StartTransaction( _ 
        oAssyDoc, "Sketches Off")

'Check all referenced docs
Dim oDoc As Inventor.Document
For Each oDoc In oAssyDoc.AllReferencedDocuments
    'set Sketch visibility
    For Each oSketch In oDoc.ComponentDefinition.Sketches
    oSketch.Visible = wfBoolean
    Next    
    
Next

'end transaction for single undo
trans.End 

'upate the files
InventorVb.DocumentUpdate()

The Problem is to get access to the activedocument compdefinitionobject.

 

in ilogic they know inventor.Document. But in C# its not possible to access trough Inventor.Document object.

 

public void HideSketches()
        {
            bool result = false;
            if (result == true)
            {
                Inventor.Transaction oTrans = myCad.InvApp.TransactionManager.StartTransaction(myCad.InvApp.ActiveDocument, "Sketches off");
                foreach (Inventor.Document oDoc in myCad.InvApp.ActiveDocument.AllReferencedDocuments)
                {
                    foreach (Inventor.Sketch oSketch in oDoc.ComponentDefinition.Sketches)
                    {
                        oSketch.Visible = result;
                    }
                }

                oTrans.End();
                oDoc.Update();
            }
        }

i used a bool for testing, later i will implement the dialog. The Problem here is, the linepart oDoc.componentDefinition is not possible.

 

i have the same problem in a lot of codesnippets. where the actual DocType is not clear while programming.

 

Please help.

 

THanks 

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).
0 Likes
Accepted solutions (1)
1,625 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable

Can you please elaborate on this:

"But in C# its not possible to access trough Inventor.Document object."

What exactly can you not access through the Inventor.Document object in C#?

I would like to help but need a clearer understanding of the problem.  Thanks.

0 Likes
Message 3 of 5

MechMachineMan
Advisor
Advisor

Okay?

 

So do a test on the Inventor.Document to see what it's proper type is, and cast the object to a properly typed variable.


--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 4 of 5

Anonymous
Not applicable
Accepted solution

I agree that portion of the SDK seems a bit peculiar since the various XXXDocument types are not actually derived from Document.  However, I have proceeded with code like this to deal with that in C# and it has worked for me...

   invDoc = invApp.ActiveDocument;
   if (invDoc != null && invDoc.DocumentType == DocumentTypeEnum.kPartDocumentObject)
   {
      fileTextBox.Text = invDoc.FullFileName;

      PartDocument partDoc = invDoc as PartDocument;

      if (partDoc != null)

      {

         PartComponentDefinition partComponentDefinition = partDoc.ComponentDefinition;

         ...


Message 5 of 5

Ruffy85
Collaborator
Collaborator

yep ok that works thanks

If my reply was helpful, please give a "Kudo" or click the "Accept as Solution" button below (or both).
0 Likes