OPENING DRAWING DIRECTLY FROM MODEL - MODEL & DRG NAME PLUS LOCATION DIFFERENT

OPENING DRAWING DIRECTLY FROM MODEL - MODEL & DRG NAME PLUS LOCATION DIFFERENT

sguan1212
Enthusiast Enthusiast
3,281 Views
46 Replies
Message 1 of 47

OPENING DRAWING DIRECTLY FROM MODEL - MODEL & DRG NAME PLUS LOCATION DIFFERENT

sguan1212
Enthusiast
Enthusiast

I found this query on an old post that are UNSOLVED. Time has change, revisitation is merited.

 

All the companies I've work for, both model name & drawing name are always different & saved in 2 different sub-folders under the same project folder. Therefore i've never had the luxury to use OPEN DRAWING command from the model. (Understanding that the model name & drawing name needs to be the same and in common location to work).

 

Has anyone workout a way get around this?

This problem has been bugging me for years. Any help would be appreciated.

Regards,

Sean

 

0 Likes
Accepted solutions (1)
3,282 Views
46 Replies
Replies (46)
Message 2 of 47

marcin_otręba
Advisor
Advisor

I would do this this way:

 

when saving drawing add_in which fires onsaveevent would write drawing.fullfilename to referencing model custom iproperty named for example draw_name.

then you can use oUserInputEvents.OnActivateCommand

if name of command = CMxOpenDrawingCmd then

inventor.documents.open(draw_name)

end if

or create new button or something

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 3 of 47

sguan1212
Enthusiast
Enthusiast

Hi, sorry i couldn't follow your recommendation.

Is it possible for you to make it more clearer for me. I'm having trouble understanding how to set this up

0 Likes
Message 4 of 47

marcin_otręba
Advisor
Advisor

You need to have add in (or vba, or ilogic) for this.

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 5 of 47

sguan1212
Enthusiast
Enthusiast

Let's say go with ilogic.

I still need more clarifications on how to implement this. I didn't fully comprehend how this is done from your first response.

Perhaps I'm a bit slow. I will spend more time to scrutinise.

 

 

0 Likes
Message 6 of 47

marcin_otręba
Advisor
Advisor

1. when saving .idw code must get referenced 3d model (or models)

2. create in 3d model custom iproperty in which you will write .idw fullfile name (path & name)

3. save 3d model.

 

 different code will use such custom iproperty and open drawing - fullfilename is stored in that iproperty.  this code should be fired from 3d model.

 

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 7 of 47

Anonymous
Not applicable

Hi Sean,

 

We have this ilogic to open our drawings from a different location than the model.

Hope this helps.

SyntaxEditor Code Snippet

'enable types that are contained in the given namespace to be referenced directly

Imports System.IO



iLogicVb.UpdateWhenDone = True



'define the active drawing

fname = ThisDoc.FileName(False) 'without extension

'MessageBox.Show(fname)

idwname = fname & ".idw"

'MessageBox.Show(idwname)



Dim oDoc As Document

oDoc = ThisApplication.ActiveEditDocument



Dim oName2 As String

oName2 = "DP" & Left(oDoc.DisplayName, 3)  'assumes project number in file name is 6 chrs

'MessageBox.Show(oName2)



Dim sRootDrive As String 

sRootDrive = "C:\Vault Workspace\Engineering\DP Register\"



'expects to find only one

Dim dirs As String()

Dim dir As String     

Dim oTargetFolder As String

Try

    'look for all directories starting with project number using * as a wildcard

    'dirs = Directory.GetDirectories(path to search, what to search for)

    dirs = Directory.GetDirectories(sRootDrive,"*" & oName2 & "*")

    'dirs1 = Directory.GetDirectories(dirs,"*" & idwname)



    'get subdirectory and set variable

    For Each dir In dirs

        If dir.Contains(oName2) Then

        oTargetFolder = dir

        End If

    Next        

Catch

    oTargetFolder = "" 

End Try



'catch empty variable

If oTargetFolder = "" Then

MessageBox.Show("Path for IDW could not be found.", "iLogic")

Return

Else



'code to open idw file

ThisDoc.Launch(oTargetFolder & "\Drawings\" & idwname)





End If
0 Likes
Message 8 of 47

sguan1212
Enthusiast
Enthusiast

Hi jtonybazy

that code didn't work for me.

I'm not very good at editing this sort of stuff. Are you able to indicate which particular line might require editing to suit my file structure.

Your model & drawing are in different location, but are the name still the same or different? 

0 Likes
Message 9 of 47

sguan1212
Enthusiast
Enthusiast

If this simple english, then i still don't understand it

0 Likes
Message 10 of 47

chandra.shekar.g
Autodesk Support
Autodesk Support

@sguan1212,

 

Try below iLogic code to open drawing from model. (code works for .idw drawings)

 

 
'enable types that are contained in the given namespace to be referenced directly
 
iLogicVb.UpdateWhenDone = True 

'define the active drawing

fname = ThisDoc.FileName(False) 'without extension

'MessageBox.Show(fname)

idwname = fname & ".idw"


Dim oDoc As Document

oDoc = ThisApplication.ActiveEditDocument

Dim sRootDrive As String 

sRootDrive = ThisDoc.Path 
'expects to find only one
Dim newPath As String = System.IO.Path.GetFullPath(System.IO.Path.Combine(sRootDrive, "..\"))

Dim dirs As String()

Dim dir As String     

Dim oTargetFolder As String

Try

    'look for all directories starting with project number using * as a wildcard
    dirs = System.IO.Directory.GetFiles(sRootDrive) 
    'get subdirectory and set variable

    For Each dir In dirs

        If dir.Contains(idwname) Then 
        	oTargetFolder = dir

        End If

    Next        

Catch

    oTargetFolder = "" 

End Try



'catch empty variable

If oTargetFolder = "" Then

MessageBox.Show("Path for IDW could not be found.", "iLogic")

Return

Else



'code to open idw file

ThisDoc.Launch(oTargetFolder)

End If

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 11 of 47

marcin_otręba
Advisor
Advisor

1. create external rule  and paste :

If ThisDoc.Document.subtype="{BBF9FDF1-52DC-11D0-8C04-0800090BE8EC}" Then
doc = ThisDrawing.ModelDocument
    Dim oCompDef As ComponentDefinition
    oCompDef = doc.ComponentDefinition
    Dim custompropset As PropertySet
    custompropset = doc.PropertySets.Item("Inventor User Defined Properties")
Try
    Call custompropset.Add(ThisDoc.PathAndFileName(True), "drawing-ref")
Catch
    custompropset.item("drawing-ref").Value=ThisDoc.PathAndFileName(True)
End Try
doc.Save
End If

Then set it up to be fired when document is saved.

Open any drawing and save it.

Open model from that drawing and :

2. make second external rule :

Dim draw_ref as String =""
    doc = ThisDoc.Document
    Dim oCompDef As ComponentDefinition
    oCompDef = doc.ComponentDefinition
    Dim custompropset As PropertySet
    custompropset = doc.PropertySets.Item("Inventor User Defined Properties")
    
Try
draw_ref= custompropset.item("drawing-ref").Value
Catch


End Try

If draw_ref <> "" Then
ThisApplication.documents.Open(draw_ref)
End If

 and run it in your model

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 12 of 47

sguan1212
Enthusiast
Enthusiast

Hi Chandra, this ilogic rule didn't work.

it came up with a message saying 'path for IDW could not be found.'

0 Likes
Message 13 of 47

sguan1212
Enthusiast
Enthusiast

Hi Marcin,

Thanks for following up on this post.

I've done what you've suggested. Adding 1st rule in the drawing and 2nd in the model.

Did a few trials and it seems to work perfectly until i trail this rule on an assembly then it failed.

Please see attachment for the error message

This was real close. If the rules works for the assembly, then this would be a win.

The rule doesn't work in both the assembly drawing and the assembly model.

 

0 Likes
Message 14 of 47

marcin_otręba
Advisor
Advisor

hi,

 

on your photo i see opened drawing and rule open drg from model... so maybe it is possible that you run rule  (that you supposed to run in model )in drawing?

Please check it first because for me it works perfectly.

Then you could create rule that will open each draing from your workspace and run that rule and write properties to models.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 15 of 47

sguan1212
Enthusiast
Enthusiast

Hi Marcin,

the rule in the drawing is triggered when saved, the message shows the moment when i save and the rule refuses to work.

I have the rule in the model as well, and when i run it, the same message appears.

Note again that this is happening only with an assembly model.

The rules works fine when handling just parts

0 Likes
Message 16 of 47

marcin_otręba
Advisor
Advisor

As i said i checked and for me it works.

Could you place yor files here?  Maybe they ale read -only? Could show more info tab on error message?

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes
Message 17 of 47

Jesper_S
Collaborator
Collaborator

Hi.

 

Im not that great with iLogic but manage to put this toghter. Not tested much but seems to work for me.

 

Put this in the drawing, trigger to run after save.

modelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)

fname = ThisDoc.PathAndFileName(False)

Try
iProperties.Value(modelName, "Custom", "IDW Name Full") = fname & ".idw"
Catch
End Try

Then in the 3D-model, put this code.

oPath = ThisDoc.Path

Try
IDWname = iProperties.Value("Custom", "IDW Name Full")
Catch
End Try

oIDW = oPath & "\" & IDWname

Try

ThisApplication.Documents.Open(IDWname, True)

Catch

MessageBox.Show("No Drawing was found linked to this model, or the Drawing has not been saved.", "No Drawing")

End Try

//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Message 18 of 47

chandra.shekar.g
Autodesk Support
Autodesk Support

@sguan1212


@sguan1212 wrote:

Hi Chandra, this ilogic rule didn't work.

it came up with a message saying 'path for IDW could not be found.'


Currently, drawing file is searched in one step back folder. Can you please share project folder hierarchy of model and drawing? so that, code can be modified accordingly.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 19 of 47

sguan1212
Enthusiast
Enthusiast

Hi Marcin,

I've attached the files for you to  have a look.

At the moment, only the assembly drawing couldn't open the drawing. The parts can open drawings okay.

There is 1 or 2 time where i got everything drawing to open okay, then i close them all down, to open it again, then is broken again. I couldn't quiet figure out the pattern of failure. Is hard to explain.

1 minute it worked, then next minute it doesn't

0 Likes
Message 20 of 47

sguan1212
Enthusiast
Enthusiast

Hi  Chandra,

I tried your again, it is confirmed not to be working. 

Please see attached image showing the file structure

0 Likes