Macro that allows SLDDRW conversion in PDF/DWG with checkbox and userfrom

Hi all

I am currently modifying an existing macro so that it adapts to my constraints.

The existing macro allows conversion of SLDDRW file to PDF and DXF with the choice of source and destination folder and change the name following the revision of the plan.

Brief...

In my case I would like to convert to PDF and DWG without worrying about the revision but that we can have a choice (like checkbox between PDF and DWG.

I managed to make some changes (like removing everything related to the revision) and modify DXF to DWG and insert my chexboxes on the Userfrom.

But on the other hand, for the coding of the checkboxes I have a problem (knowing that I don't have a lot of bottle in VBA, I tried something but hey).

If you have an idea?

Thank you:)

Here's some of the code:

Private Sub FiltreBox_Change()
StartConvert.Enabled = False
TextSource.Caption = "Validate source directory"
TextSource.ForeColor = RGB(255, 0, 0)
OkSource = False
CheckSource.Enabled = True
End Sub


Private Sub SourceBox_Change()
StartConvert.Enabled = False
TextSource.Caption = "Validate source directory"
TextSource.ForeColor = RGB(255, 0, 0)
OkSource = False
CheckSource.Enabled = True
End Sub
Private Sub CheckBox1_Click()

End Sub

Private Sub CheckBox2_Click()

End Sub

Private Sub StartConvert_Click()
Set swApp = Application.SldWorks

TimeDebut = Timer
DestinationFileNumber = 0
FileName = Dir(PathDepart & FilterBox.Value & ". SLDDRW")
' Begins the loop

Do While FileName<> ""
DestinationFileNumber = DestinationFileNumber + 1
Advance.Caption = "Processing File" & DestinationFileNumber &" / " & FileSource Number & " : " & FileName
SaveDir.Repaint
FileNameWithoutExtension = Left(FileName, Len(FileName) - 7)
Opening the file
Set Part = swApp.OpenDoc6(PathDepart & FileName, 3, 0, "", longstatus, longwarnings)
swApp.OpenDoc6 PathDepartir & FileName, 3, 0, "", longstatus, longwarnings
Set Part = swApp.ActivateDoc2(FileName, False, longstatus)
Set swCustPrpMgr = Part.Extension.CustomPropertyManager("")
Creation of the pdf file
If CheckBox1.Value = True Then
Part.Extension.SaveAs PathArrival & FileNameWithoutExtension & ".pdf", 0, 0, Nothing, longstatus, longwarnings
End If
'Creating the dwg file
If CheckBox1.Value = True Then
Part.Extension.SaveAs PathArrivee & FileNameWithoutExtension & ".dwg", 0, 0, Nothing, longstatus, longwarnings
End If
'Closure of the plan
Set Part = Nothing
swApp.CloseDoc FileName

FileName = Dir ' Gets the following entry.
Loop

StartConvert.Enabled = False
TimeFin = Timer

Progress.Caption = "Operation completed." & DestinationFileNumber & " / " & FileSourceNumber&" file(s) processed. Elapsed Time: " & TimeSerial(0, 0, TimeFin - TimeDebut)

 

End Sub

Private Sub UserForm_Initialize()
OkSource = False
OkSource = False
StartConvert.Enabled = False
FiltreBox.Value = "*"
TextSource.Caption = "Introduce and validate the source directory"
TextSource.ForeColor = RGB(255, 0, 0)
TextDestination.Caption = "Enter and validate the destination directory"
TextDestination.ForeColor = RGB(255, 0, 0)
SourceBox.Value = "Z:\deals"
DestinationBox.Value = "Z:\deals"
Advancement.Caption = ""
End Sub

Hello

Specify the roles of CheckBox1 and CheckBox2 and what you want to do with them.

The principle of operation of a checkbox:

It has a Value property that varies between True and False.

To use this change, you must use the Click event.

Example:

Private Sub CheckBox1_Click()
     If CheckBox1.Value = True Then
          MsgBox ("Action so true")
     ElseIf CheckBox1.Value = False Then
          MsgBox ("Action if false")
     End If

End Sub

 

3 Likes

Okay, thank you,

I'm going to try. I'll keep you up to date ;)

 

1 Like

it works, it's great!

yet another thing,

I would like to put an error msgbox if no checkbox is checked.

I thought I'd write this:

Sub msgbox()
If CheckBox1.Value = False Then
ElseIf CheckBox2.Value = False Then
Select Case msgbox("Please choose a conversion please!", vbExclamation, "Conversion error")
End Sub

1 Like

For your code:

Sub msgbox()
     If CheckBox1.Value = False and CheckBox2.Value = False Then
          Msgbox("Please choose a conversion please!", vbExclamation, "Error conversion")
     End If
End Sub

 

But in programming, if possible,  it's always better not to allow the user to do something stupid instead of telling them that they did one.

That's why I think you have a button in your Userform that starts the conversion. Let's imagine that you have appointed him Bouton_Lancement.

Private Sub CheckBox1_Click() 'This sub already exists so add the code below

     If CheckBox1.Value = False and CheckBox2.Value = False Then
          Bouton_Lancement.Visible = False    
     Else if CheckBox1.Value = True Or CheckBox2.Value =  True Then
          Bouton_Lancement.Visible = True
     End If

End Sub

Then do the same with the function of the event CheckBox2_Click

This code will allow you to make the launch button invisible so it's impossible to continue. It will therefore not be necessary to reprimand the user ;-)

Hoping to have helped you.

3 Likes

Hello

Do you have the link to download the basic macro please? 

Thanks in advance

Thank you for your answer,

I'll look at it and tell you if it works.

 

RazFlash: I'm looking for it and if I find it I'll give you the link.

He gives me a mistake when I put the second solution.

"Compilation error:

This instruction must be the first in the line"

the -> line "Else If CheckBox1.Value = True or CheckBox2.Value =  True Then" is written in red

Razflash:

I couldn't find the original link...

But I have the original file.

I have attached it.


savediraspdf_v1.1.zip

Space error:

Private Sub CheckBox1_Click() 'This sub already exists so add the code below

     If CheckBox1.Value = False and CheckBox2.Value = False Then
          Bouton_Lancement.Visible = False    
     ElseIf CheckBox1.Value = True Or CheckBox2.Value =  True Then
          Bouton_Lancement.Visible = True
     End If

End Sub

Thanks for the file! 

Dsl of the return.

 

Thank you, it works very well.

 

I will still have other changes to make I think especially at the level of the source folder and the destination file where I would like to have a browse button instead of pasting the link, but I will do it later.

 

Thank you remrem.

Hello

But you're welcome...

Feel free to ask more questions for your improvements.

Have a nice day.