req: small macro to save idw

req: small macro to save idw

Anonymous
Not applicable
422 Views
10 Replies
Message 1 of 11

req: small macro to save idw

Anonymous
Not applicable
Our numbering in the company for moddels is a 10 digit number followed by -M1 for parts as for assy.
When we save a drawing this will become automaticlly the 10 digit number with -M1. We always need to change the M1 to 01.
Can someone write me a code with replaces the M with a 0 and then saves it automaticlly?

so for instance you make a drawing you put on a view of a part or an assy with a number like 1624254800-M1 you start the macro and it wil save it as 1624254800-01.idw

thx in advance!
Stefaan
0 Likes
423 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
"Can someone write me a code ... "

How much are you paying?

:-))
0 Likes
Message 3 of 11

Anonymous
Not applicable
how about a thx on my site? That's all I can offer...
I don't thinck the code will be that long no? Message was edited by: Stefaan Boel
0 Likes
Message 4 of 11

Anonymous
Not applicable
I only made the comment in jest.

If I can help I will, but I don't have a ready solution at the moment.

I did find these that may help -

http://discussion.autodesk.com/thread.jspa?messageID=1080291

http://www.mcadforums.com/forums/viewtopic.php?t=3857&highlight=rename+idw+file

Maybe there's someone else out there...
0 Likes
Message 5 of 11

Anonymous
Not applicable
you`re in luck
i have just finished something similar a couple of days ago
here ya go

Public Sub saveas()
Dim oApp As Application
Dim oCurrentDoc As Document

Set oApp = ThisApplication
Set oCurrentDoc = oApp.ActiveDocument

sPartFileName = oCurrentDoc.ReferencedFiles(1).DisplayName

Dim words() As String
Dim Delimiter As String

Delimiter = "-"

' Split the string at the "-" characters.
words() = Split(sPartFileName, Delimiter)

sM1 = Left(words(1), 2)

Dim spath As String
spath = "C:\"

If sM1 = "M1" Then

oApp.SilentOperation = True
Call oCurrentDoc.saveas(spath & words(0) & "-" & "01" & ".idw", False)

End If

End Sub


That would be 100$ payed by the end of the millenium
:) Message was edited by: cozmin
0 Likes
Message 6 of 11

Anonymous
Not applicable
Hello Cozmin,

thx a lot, this works perfectlly!!!

by the way, if i'm still alive by then and Inventor still excists i'll pay you that $100, just remind me 🙂

until next time!
Stefaan
0 Likes
Message 7 of 11

Anonymous
Not applicable
I wanted to add some extra code, so when you click on it again you just do a normal save since the file already excists (that's what he's checking)

Public Sub saveas01()
Dim oApp As Application
Dim oCurrentDoc As Document

Set oApp = ThisApplication
Set oCurrentDoc = oApp.ActiveDocument

Set fs = CreateObject("Scripting.FileSystemObject")
sFileName = oCurrentDoc.DisplayName
Dim spath As String
spath = "C:\Working_Dir_Smarteam\"

If fs.FileExists(spath & sFileName) Then
oApp.SilentOperation = True
Call oCurrentDoc.Save

Else
sPartFileName = oCurrentDoc.ReferencedFiles(1).DisplayName

Dim words() As String
Dim Delimiter As String

Delimiter = "-"

' Split the string at the "-" characters.
words() = Split(sPartFileName, Delimiter)

sM1 = Left(words(1), 2)

If sM1 = "M1" Then

oApp.SilentOperation = True
Call oCurrentDoc.saveas(spath & words(0) & "-" & "01" & ".idw", False)

End If
End If
End Sub
0 Likes
Message 8 of 11

Anonymous
Not applicable
you have to redo all the words() stuff
delimitedstring= ocurentdoc.name
...
if sM1 = "01" Then
oApp.SilentOperation = True
Call oCurrentDoc.save
end if
if this is what you want
0 Likes
Message 9 of 11

Anonymous
Not applicable
So, this is what i'm having now.
I changed this line to displayname
Delimitedstring = oCurrentDoc.DisplayName

But now the strange thing is when I click it it does the save to the idw, click again it does a save.
Next time I click it debugs!?! I end it, click it again and it saves.
Again seconde time debugs.
why?

Public Sub saveas02()
Dim oApp As Application
Dim oCurrentDoc As Document

Set oApp = ThisApplication
Set oCurrentDoc = oApp.ActiveDocument

Dim spath As String
Dim wordsdoc() As String
Dim wordslink() As String
Dim Delimiter As String

spath = "C:\Working_Dir_Smarteam\"

'Link filename and referenced file name to parameter
Delimitedstring = oCurrentDoc.DisplayName
sPartFileName = oCurrentDoc.ReferencedFiles(1).DisplayName
Delimiter = "-"

' Split the string at the "-" characters.
wordsdoc() = Split(Delimitedstring, Delimiter)
s01 = Left(wordsdoc(1), 2)
wordslink() = Split(sPartFileName, Delimiter)
sM1 = Left(wordslink(1), 2)

'Do a doc save
If s01 = "01" Then
oApp.SilentOperation = True
Call oCurrentDoc.Save

Else

If sM1 = "M1" Then
oApp.SilentOperation = True
Call oCurrentDoc.saveas(spath & wordslink(0) & "-" & "01" & ".idw", False)

End If
End If
End Sub
0 Likes
Message 10 of 11

Anonymous
Not applicable
perhaps there is a save watch
if the doc is saved then it doesnt perform onether save until you change something in the doc (just a guess)
pu this statement the first line after the
Public Sub saveas02()

On Error Resume Next

and it will skip the error
0 Likes
Message 11 of 11

Anonymous
Not applicable
Life can be so easy!

I thank you a lot for helping me out until I got it right!
0 Likes