-
Re: How do you code a macro to point to the default assembly template location?
Matt Martens May 2, 2016 12:14 PM (in response to Alfred Jelinek)Use ISldWorks::GetUserPreferenceStringValue with swDefaultTemplateAssembly as your argument.
-
Re: How do you code a macro to point to the default assembly template location?
Alfred Jelinek May 2, 2016 12:55 PM (in response to Matt Martens)Matt,
thank you for the reply....how would I use it?
sorry trying to learn as I go.
Thanks,
Al
-
-
Re: How do you code a macro to point to the default assembly template location?
roberto gennari May 2, 2016 12:22 PM (in response to Alfred Jelinek)I use this macro
Dim swApp As SldWorks.SldWorks
Sub main()Set swApp = Application.SldWorks
Dim myPath As String
myPath = "C:\Users\aljel\Desktop\Mill Tool Templates - 2016\templates\Assembly.asmdot"swApp.SetUserPreferenceStringValue swUserPreferenceStringValue_e.swDefaultTemplateAssembly, ""
swApp.SetUserPreferenceStringValue swUserPreferenceStringValue_e.swDefaultTemplateAssembly, "myPath"End Sub
Thanks
Roberto
-
Re: How do you code a macro to point to the default assembly template location?
Alfred Jelinek May 2, 2016 12:54 PM (in response to roberto gennari)Roberto,
would I replace:
Set Part = swApp.NewDocument("C:\Users\aljel\Desktop\Mill Tool Templates - 2016\templates\Assembly.asmdot", 0, 0, 0)
I get an error at:
longstatus = Part.SaveAs3(LocationInfo.Caption, 0, 2)
when I comment out the "mypath" stuff to test the default template location code.
I ultimately would like to remove the reference to c:\users\aljel\desktop......
thanks
Al
-
-
Re: How do you code a macro to point to the default assembly template location?
Matt Martens May 2, 2016 1:02 PM (in response to Alfred Jelinek)Use a string variable to catch the value and plug that in as the argument from NewDocument.
Dim template as String
Set swApp = _
Application.SldWorkstemplate = swApp.GetUserPreferenceStringValue(swDefaultTemplateAssembly)
Set Part = swApp.NewDocument(template, 0, 0, 0)-
Re: How do you code a macro to point to the default assembly template location?
Alfred Jelinek May 2, 2016 1:16 PM (in response to Matt Martens)Thanks Matt...
I am getting an error at:
longstatus = Part.SaveAs3(LocationInfo.Caption, 0, 2)
LocationInfo.Caption is coded above this as:
Private Sub SelectFolderButton_Click()
If Okay.Visible = True Then Okay.Visible = False
If JobNumber.Text = "" Then JobNumber.Text = "Enter a Job Number"
'error if box is empty
If FileName.Text = "" Then FileName.Text = "Main_Die_Assy"
AppearAs.Caption = JobNumber.Text + "-" + FileName.Text 'caption filled
Dim myPath As String
myPath = SelectFolder("Select Folder to Save Assembly File", "")
If Len(myPath) Then
'MsgBox MyPath
LocationInfo.Caption = myPath + "\" + AppearAs.Caption + ".sldasm"
Okay.Visible = True
Okay.Value = False
Else
MsgBox "Cancel was pressed"
End If
End Sub
Again I truly appreciate your help!!
Al
-
Re: How do you code a macro to point to the default assembly template location?
Deepak Gupta May 2, 2016 1:48 PM (in response to Alfred Jelinek)Are you saving the file as copy? The 2 in this line is for save as copy.
longstatus = Part.SaveAs3(LocationInfo.Caption, 0, 2)
Have you tried using swModel.Extension.SaveAs
-
Re: How do you code a macro to point to the default assembly template location?
Alfred Jelinek May 2, 2016 6:28 PM (in response to Deepak Gupta)Deepak,
First of all.....thank you very much for all of your help with all my coding issues!
Thank you for the suggestion....I tried it...I get an error with the code I am trying...tried it a couple of ways...
'longstatus = Part.SaveAs3(LocationInfo.Caption, 0, 2) (the old stuff)
Dim Location1 As String
Location1 = LocationInfo.Caption
swModel.Extension.SaveAs Location1, swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, errors, warningsI also tried omitting the dim and location1 code and simply using LocationInfo.Caption in the above example.
LocationInfo.Caption is where I get the folder path and file name:
LocationInfo.Caption = myPath + "\" + AppearAs.Caption + ".sldasm"
I attached the failing macro...it works fine if I leave the ("c:\users\aljel\....)
the code is under the "savebutton_click" then " 'create new assembly"
Any ideas or tips would be greatly appreciated.
Thanks again!
Al
-
Create the Main_Die_Assy.swp.zip 49.5 KB
-
Re: How do you code a macro to point to the default assembly template location?
Deepak Gupta May 3, 2016 12:50 AM (in response to Alfred Jelinek)Here is updated macro. I made these changes.
Added declarations
Commented this line
Changed swModel to Part here
-
Create the Main_Die_Assy.swp.zip 64.2 KB
-
Re: How do you code a macro to point to the default assembly template location?
Alfred Jelinek May 3, 2016 3:07 AM (in response to Deepak Gupta)Deepak,
Thanks again for your help....I tried to run your updated macro as well as apply it to my copy. Unfortunately I get the following error:
I appreciate that you also showed me what you did...makes perfect sense to me and I am learning...thank you...
when I hover over each attribute each shows its value and all seems okay to me...location1 shows perfect when hovered over.
what would cause this error?
Thank you and I hope you have a great day!
Al
-
Re: How do you code a macro to point to the default assembly template location?
Deepak Gupta May 3, 2016 3:19 AM (in response to Alfred Jelinek)The macro is working fine for me. What is your SW version?
Can you post the declarations you've added?
-
Re: How do you code a macro to point to the default assembly template location?
Alfred Jelinek May 3, 2016 8:37 AM (in response to Deepak Gupta)Deepak,
Sorry for the mess...I do appreciate your help! I am using SolidWorks Premium 2016 SP3 on Win10Pro_64bit.
(general) Declarations are:
Dim swApp As Object
Dim Part As Object
Dim tmpPath As String
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim errors As Long, warnings As Long
I also call out:
Dim Location1 As String
in this context:
Dim Location1 As String
Location1 = LocationInfo.Caption
Part.Extension.SaveAs Location1, swSaveAsCurrentVersion, swSaveAsOptions_Silent, Nothing, errors, warnings
I hope this is what you asked for...I plan on taking Keith Rice's course in the future but unfortunately I am out of commission with a back injury and funds are low at the moment.
The reason I am creating this is... as a die designer I would love to use Logopress3 but the cost is too much right now....and designing Dies with Solidworks alone is a pain in the behind....so I am trying to...in the event my surgeons find a solution to my injury which now looks like the chances are low to none....create some tools I can use to make my job and hopefully other's jobs easier in the process by sharing these macros.
Originally this large macro was 6 or 7 smaller ones I created to use together in sequence...learning SolidWorks API can be a pain but it definitely helps to pass the time....and I am learning a ton thanks to you, @Keith Rice and many others here on the forum. This stuff, learning SW API/macros, is definitely the most challenging SW has been for me since I began using it. Becoming a CSWE was a breeze in comparison.
Thanks again!
Respectfully,
Al
-
Re: How do you code a macro to point to the default assembly template location?
Deepak Gupta May 3, 2016 8:39 AM (in response to Alfred Jelinek)No worries Al and we wish you speedy recovery.
Let me test the codes on SW016 SP3
-
Re: How do you code a macro to point to the default assembly template location?
Alfred Jelinek May 3, 2016 8:44 AM (in response to Deepak Gupta)Thank you very much!
I am in Kewaskum, WI, USA...where are you from?
-
Re: How do you code a macro to point to the default assembly template location?
Deepak Gupta May 3, 2016 8:54 AM (in response to Alfred Jelinek)I'm based in India.
The macro works great on SW2016 SP3.0, so check these settings on your machine.
Try once again as I've made some minor changes in the attached macro.
-
Create the Main_Die_Assy.swp.zip 55.2 KB
-
Re: How do you code a macro to point to the default assembly template location?
Alfred Jelinek May 3, 2016 9:11 AM (in response to Deepak Gupta)Deepak...
Holy smokes! I went to the default template settings...."Always..." was selected...
however the "Assemblies:" box had "mypath3" in it instead of the actual path (c:\...)....I clicked the "..." button reset the assembly template location....and now the original macro solution works...perfectly!!
Very weird...not sure how/why that would have gotten changed to "mypath3"...
However.....
Thank you, thank you, thank you!!!
You sir are a gentleman and a scholar!
I truly hope you have an awesome day, as you have made mine!!
Al
-
Re: How do you code a macro to point to the default assembly template location?
Deepak Gupta May 3, 2016 10:15 AM (in response to Alfred Jelinek)Sounds great. I should have mentioned to check to default template path too.
Very weird...not sure how/why that would have gotten changed to "mypath3"...
Could have been result of some macro.
-
-
-
-
-
-
-
-
-
-
-
-