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,285 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,286 Views
46 Replies
Replies (46)
Message 21 of 47

sguan1212
Enthusiast
Enthusiast

Hi Jesper,

Thanks for your input.

I've tested your rules. It seems to work okay, but still have flaws in it.

When I close off a drawing, it will ask me if i want to save it, even though I've just saved the drawing.

And there is a message which comes up here and there, 1 that I've never came across in the past. See attachment

 

0 Likes
Message 22 of 47

chandra.shekar.g
Autodesk Support
Autodesk Support

@sguan1212,

 

Try below iLogic code. In this, root directory is hard coded and can be changed in future.

 

'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 = "C:\Vault\Designs\"
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



0 Likes
Message 23 of 47

sguan1212
Enthusiast
Enthusiast

Hi Chandra,

I've added the rule into a part and then produce the drawing.

But this rule still doesn't work, The message is still 'path for IDW could not be found'

0 Likes
Message 24 of 47

Jesper_S
Collaborator
Collaborator

Hi.

 

Besides that you get the "Save" prompt, it can open the drawings both for .iam and .ipt?

 


//Jesper

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

Jesper_S
Collaborator
Collaborator

Hi Chandra.

 

Does your code assume that the drawingname and model name is the same?


//Jesper

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

chandra.shekar.g
Autodesk Support
Autodesk Support

@Jesper_S wrote:

Hi Chandra.

 

Does your code assume that the drawingname and model name is the same?


@Jesper_S,

 

Yes, Assuming that drawing name and model name are same.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 27 of 47

Jesper_S
Collaborator
Collaborator

From his first Post

"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. "

 

 


//Jesper

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

sguan1212
Enthusiast
Enthusiast

Hi Jesper,

This is exactly how it goes.

After my 1st save,  without any additional editing/changes made to the drawing, I went straight to close, then the save prompt pops up. If I click save, then the rules you've created will work fine. But if i don't go ahead with the prompted save, the model will open up another test drawing that I've created earlier which is of a different part.

So for this to work. I must click save if it is prompted. This can become a nuisance especially when we handle large bunch of drawings at a time.

Have we reached an impasse?

This is where Inventor is behind. Such a basic feature really should be a standard command. The existing OPEN DRAWING

command seems like such a half hearted effort from Autodesk. I really would like to know the percentage of inventor users who actually save model and drawing as the same name and location, just to be able to use this command. It makes no sense, they shouldn't belong in a common area.

Apologies for the lamentation.

If there is more that can be done, please help...

0 Likes
Message 29 of 47

Jesper_S
Collaborator
Collaborator

What kind of Trigger do you have set for the iLogicrule?

Now I'm just guessing, but when the rule i triggered, it sets the Custom iProperty in the model via the drawing, then the drawing senses a change in the model and thats why you get the saveprompt. 

Does it looks like this?

Capture.JPG

No save for the drawing but for the 3D-model.

 


//Jesper

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

sguan1212
Enthusiast
Enthusiast

Hi Jesper,

I will do some more testing based on your rule tomorrow at work to see if there is anything else that can shed light on this issue.

However, you have alerted me of something. Your rule are set to be triggered after save. I will change it to be triggered before save and see how it behaves

0 Likes
Message 31 of 47

Jesper_S
Collaborator
Collaborator

Hi.

 

I think it wont work.

It can't write the drawings filename and path Before it has been saved the first time. At that point it doesnt have any name or path.

If you do so you have to save it twice.


//Jesper

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

marcin_otręba
Advisor
Advisor

hi,

 

i modified my original idea:

 

1. create external rule  and paste :

If ThisDoc.Document.subtype="{BBF9FDF1-52DC-11D0-8C04-0800090BE8EC}" Then
Try
name=""
name= ThisDoc.PathAndFileName(True)
Catch

End Try
If name <>""
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")
        doc.Save
    Catch
    If custompropset.item("drawing-ref").Value<>ThisDoc.PathAndFileName(True) Then
        custompropset.item("drawing-ref").Value=ThisDoc.PathAndFileName(True)
        doc.Save
    End If
    End Try

End If
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 33 of 47

sguan1212
Enthusiast
Enthusiast

Hi Marcin,

That is still no good. see attached image for error message.

I went through 5 new parts with the rules, they work fine. Is when I do the assembly drawing of the 5 parts, the rule breaks after save.

Then I close off every files, then open the assembly drawing alone, do a save and the rule is processed okay.

Test opening drawing from the model, it work good.

Following that. I close off the every file again.

Go and open all the 5 parts and plus assembly. Test through the opening drawings, the parts rule works all okay, until I got to assembly then it refused to open the drawing again. Which is already working a few mins ago

 

0 Likes
Message 34 of 47

Jesper_S
Collaborator
Collaborator

Hi.

 

Can you please make a ScreenCast recording of all your steps with the latest code that @marcin_otręba posted.

I can't reproduce the error from your description.


//Jesper

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

sguan1212
Enthusiast
Enthusiast

Hi Jesper,

I've tested triggering your rule before save. It obviously failed as you've expected.

I figured it was rather dumb of me to even mention that, this comes to show how ignorant and incompetent I am at solving this sort of issues. 

 

Tomorrow, I will record another new test video based on Marcin's ilogic rule to show you guys

0 Likes
Message 36 of 47

Jesper_S
Collaborator
Collaborator

Hi.

 

Are you able to send your testfiles? Make a .zip and upload here?


//Jesper

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

marcin_otręba
Advisor
Advisor

hi,

 

i modified my original idea - the reason of error was that ilogic somehow remembered type of doc. i removed uselees oCompDef decaration. should work right now.

 

1. create external rule  and paste :

If ThisDoc.Document.subtype="{BBF9FDF1-52DC-11D0-8C04-0800090BE8EC}" Then
Try
name=""
name= ThisDoc.PathAndFileName(True)
Catch

End Try
If name <>""
doc = ThisDrawing.ModelDocument
    Dim custompropset As PropertySet
    custompropset = doc.PropertySets.Item("Inventor User Defined Properties")
    Try
        Call custompropset.Add(ThisDoc.PathAndFileName(True), "drawing-ref")
        doc.Save
        doc.Close (True)
    Catch
    If custompropset.item("drawing-ref").Value<>ThisDoc.PathAndFileName(True) Then
        custompropset.item("drawing-ref").Value=ThisDoc.PathAndFileName(True)
        doc.Save
        doc.Close (True)
    End If
    End Try
End If
End If

End If
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 =""

Dim doc as document
doc = ThisDoc.Document

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 38 of 47

sguan1212
Enthusiast
Enthusiast

Hi Marcin,

This rule didn't work at all. See attached image

0 Likes
Message 39 of 47

sguan1212
Enthusiast
Enthusiast

Hi Guys, 

Please see attached the video of how the rule breaks (ilogic rule by Marcin)

Plus the files that the video are produced from.

It is just really weird that it initially worked. Then after I closed it and reopened it. Then it doesn't 

 

0 Likes
Message 40 of 47

marcin_otręba
Advisor
Advisor

Delete two last "end if" statements.

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders

0 Likes