View Single Post
  #13   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default TabSritp & Multipage

If I follow the problem is here

Run-tim error '91':
Object variable or with block variable not set.
Then when I click debug. It is highligthing at:
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0,
False,
0, Nothing, 0)


Effectively earlier you had done
Set Part = Application.SldWorks.ActiveDoc
so presumably ' Part ' fully refers to ActiveDoc

Trouble is I know nothing about "SldWorks" and "ActiveDoc" or even which
application you are running this VBA. As a guess I'd look to see if
"Extension" exists as a child object of Part (ie ActiveDoc)

Dim obj as Object
' code
Set Part = etc
Set obj = Part.Extension
msgbox Not obj Is Nothing

I could be on the wrong track, maybe you need to do something else when user
switches Optionbuttons and just before calling those macros.

Regards,
Peter T



"Maperalia" wrote in message
...
Peter'
I plotted the wrong macro. Please discard the previous one.

The macro1 is:


'### START OF MACRO1 ########
Sub Revolve_Vertical_Centerline()

Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim myFeature As Object

Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc

boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0,
False,
0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line34@Sketch1",
"EXTSKETCHSEGMENT", 0.08887711938888, -0.01670467080663, 0, True, 0,
Nothing,
0)
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0,
False,
0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Line34@Sketch1",
"EXTSKETCHSEGMENT", 0.08887711938888, -0.01670467080663, 0, True, 4,
Nothing,
0)

boolstatus = Part.Extension.SelectByID2("Sketch1<2", "SKETCH", 0, 0, 0,
True, 0, Nothing, 0)
Set myFeature = Part.FeatureManager.FeatureRevolve(1.570796326795, False,
0,
0, 0, True, True, True)
Part.SelectionManager.EnableContourSelection = False

Part.ClearSelection2 True
Part.ShowNamedView2 "*Trimetric", 8


End Sub
'### END OF MACRO1 ########

"Maperalia" wrote:

Peter;
Thanks for your quick response. I followed your advise and is fixed it.
I added the following in the code you sent me:

Private Sub OptionButton1_Change()
gbCtrLineHoriz = OptionButton1.Value
If gbCtrLineHoriz Then
Call macro1
Else
Call macro2
End If
End Sub

However, after I ran I got the following error message:

Run-tim error '91':
Object variable or with block variable not set.

Then when I click debug. It is highligthing at:
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0,
False,
0, Nothing, 0)

This statement is located in the macro1 which is:


'###### START OF MACRO1 #############

Sub Revolve_Horizontal_Center()
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim myFeature As Object


Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc


boolstatus = Part.Extension.SelectByID2("Line33", "SKETCHSEGMENT",
0.003588671546553, -0.03123281095829, 0.02897111198368, True, 0, Nothing,
0)

boolstatus = Part.Extension.SelectByID2("Line33", "SKETCHSEGMENT",
0.003588671546553, -0.03123281095829, 0.02897111198368, False, 4,
Nothing, 0)

boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0,
True,
0, Nothing, 0)

Set myFeature = Part.FeatureManager.FeatureRevolve(1.570796326795, False,
0,
0, 0, True, True, True)
Part.SelectionManager.EnableContourSelection = False

Part.ClearSelection2 True
Part.ShowNamedView2 "*Trimetric", 8

End Sub
'###### END OF MACRO1 #############

Could you please tell me how to fix it?
Thanks
Kind regards.

Maperalia

"Peter T" wrote:

It probably means you do not have an Optionbutton named "OptionButton1"
on
the form.

Regards,
Peter T

"Maperalia" wrote in message
...
Peter;
Thanks for the additional code. I added in my macro and after I ran I
got
the following error message:

Run-time error '424':
Object Required

Then I click debug and it is highligthing at the following statement:

gbCtrLineHoriz = OptionButton1.Value

What does is mean? and how can I fix it please ?..

Kinr regards.
Maperalia


"Peter T" wrote:

I'm glad the previous suggestion worked for you, based on what you
had
described it didn't need too much mind reading!

But this time I have no idea what you are trying to say, all the
code you
quote does not mean anything to me.

If, and this is just a guess, you want to do something when user
changes
an
OptionButton -

Private Sub OptionButton1_Change()
gbCtrLineHoriz = OptionButton1.Value

If gbCtrLineHoriz Then
' call routine to do horizontal stuff
Else
' call routine to do vertical stuff
End If

End Sub


Previously in the form's Initialize event I suggested you do
Me.OptionButton1.Value = True

but don't do that, instead do

gbCtrLineHoriz = True

and ensure OptionButton1 is selected (its Value property = True) at
design
time.

Regards,
Peter T


"Maperalia" wrote in message
...
Peter;

OHHH!! My God you are amazing. You read my mind in this theme.
This is
exactly the form I was looking for. Thank you very much. I know
now
that I
was completely lost. I ran it and I got the message I need without
problem.

However, I would like to know how to point the selection
(horizontal or
vertical) directly to the statement because when I choose
horizontal in
the
form I got horizontal revolve and when I choose vertical in the
form I
got
horizontal revolve too.

These are the statements I have to revolve the sketch using the
horizontal
or vertical direction:

'######## Select Horizontal Centerline and Sketch1 to Revolve it
############
'Select Horizontal Centerline
boolstatus = Part.Extension.SelectByID2("Line2",
"SKETCHSEGMENT",
-0.04111859620927, -0.1015753044947, 0, False, 4, Nothing, 0)
= RevDistance ' CHANGED
THIS
TO
MY
VAR
'Select Sketch1
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0,
0, 0,
True, 0, Nothing, 0)
'Revolve it
Dim myFeature As Object
'Part.FeatureManager.FeatureRevolve RevAngle, False, 0, 0, 0, 1,
1, 1 '
CHANGED THIS TO MY VAR
Set myFeature =
Part.FeatureManager.FeatureRevolve(1.570796326795,
False,
0, 0, 0, True, True, True)
Part.SelectionManager.EnableContourSelection = False
'################################################# ######################


'######## Select Vertical Centerline and Sketch1 to Revolve it
############
'Select Vertical Centerline
boolstatus = Part.Extension.SelectByID2("Line1", "SKETCHSEGMENT",
0.142235, 0.044925, 0, False, 4, Nothing, 0)
= RevDistance ' CHANGED
THIS
TO
MY
VAR
'Select Sketch1
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 0,
0, 0,
True, 0, Nothing, 0)
'Revolve it
'Dim myFeature As Object
'Part.FeatureManager.FeatureRevolve RevAngle, False, 0, 0, 0, 1,
1, 1 '
CHANGED THIS TO MY VAR
Set myFeature =
Part.FeatureManager.FeatureRevolve(1.570796326795,
False,
0, 0, 0, True, True, True)
Part.SelectionManager.EnableContourSelection = False
'################################################# ######################


What statement should I have to target the selection I got in my
form
for
horizontal or vertical?

Kind regards
Maperalia


"Peter T" wrote:

Sounds like a pair of Optionbuttons is what you are after. These
are
mutually exclusive, so with only two only need to trap the change
event
of
one of them.

Try the following in a new project, code in a userform with
controls
as
indicated and code "Sub Test()" in a normal module

'''''''' code in Userform1
' with two "wide" option buttons
' named OptionButton1 & OptionButton2
' and a commandbutton

Public gbCtrLineHoriz As Boolean


Private Sub CommandButton1_Click()
' the OK close button
' set Cancel = True in properties
' do any validate stuff here

Me.Hide
End Sub

Private Sub OptionButton1_Change()
gbCtrLineHoriz = OptionButton1.Value

End Sub


Private Sub OptionButton2_Click()

End Sub

Private Sub UserForm_Initialize()
Me.OptionButton1.Value = True

OptionButton1.Caption = "Revolve with Horizontal Centerline"
OptionButton2.Caption = "Revolve with Vertical Centerline"

End Sub
''''' end userform code

'''' code in a normal module
Sub test()
Dim frm As UserForm1
Dim bCtrLineHoriz As Boolean

Set frm = UserForm1 ' triggers initialize event
frm.Show
' modeless form, code waits here
' until user hides or closes the form

' then code reverts here with the form and
' properties still in memory

bCtrLineHoriz = frm.gbCtrLineHoriz

Unload frm
Set frm = Nothing

If bCtrLineHoriz Then
MsgBox "Horizontal"
Else
MsgBox "Vertical"
End If

End Sub

''' end code normal module

From what I gather, the Multipage and its pages is not directly
relavant
as
far as any code is concerned.

Regards,
Peter T







"Maperalia" wrote in
message
...
Peter;

I do apologize for giving you a hard time. I believe that I am
not
choosing