Re: TabSritp & Multipage
- From: Maperalia <Maperalia@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 12 Dec 2008 08:55:01 -0800
Peter;
Thanks very much, I added the coma and it is working perfectly!!!!. Despite,
you do not have knowledge in SW. You were able to help to accomplish this
macro.I really appreciate your helping me with this matter.
For you information, I will describe what I have so you can have an idea
what I am doing.
Basically, it is a circle part that is revolved in SW. The circle part has
two dimensions to control it which are:
1.- The "Angle” to revolve the circle, and
2.- The "Distance” from the center of the circle to the center of the angle .
I setup the "angle" and "distance" to be typed in the excel spreadsheet. The
reason I did this is because I want the people in my team that do not have
knowledge in SW to update the revolve part with the new dimensions without
using SW tools. The only problem is that they have to open excel and SW files
to run it. I have not figured it out how to include in my excel macro to open
the SW part automatically. If you have any idea how to do it I will really
appreciate it.
Well, the data I have in the excel cells are:
1.- In the cell "A1" I have the "Angle" description in the cell "B1" I have
the "Angle" value.
2.- In the cell "A2" I have the "Distance" description in the cell "B2" I
have the "Distance" value.
The excel macro that reads this data and update the revolve part's dimension
in SW is:
' &&& START MACRO &&&&
Sub Circle_Dimensions()
Dim swApp As Object
Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim FeatureData As Object
Dim Feature As Object
Dim Component As Object
Set swApp = GetObject(, "SldWorks.Application")
Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID("D1@Revolve1@Circle.SLDPRT",
"DIMENSION", -0.09850135091876, -0.1943853516059, 0.08935038736053, False, 0,
Nothing)
Part.Parameter("D1@Revolve1").SystemValue = Excel.Range("B1") / 57.29577951
boolstatus = Part.Extension.SelectByID("D2@Sketch1@Circle.SLDPRT",
"DIMENSION", -0.03077633012788, -0.11670139381, 0.09386013938138, False, 0,
Nothing)
Part.Parameter("D2@Sketch1").SystemValue = Excel.Range("B2") * 0.0254
End Sub
'&&& END MACRO &&&&
I hope this information will help you for future matters.
Kind regards.
Maperalia
"Peter T" wrote:
That error is generic, appears when an attempt to automate an object (eg.
application) fails.
It's difficult to comment further because I don't know what you are doing,
or anything about "SldWorks", you haven't shown the relevant code, or even
which application the VBA code is running in.
However, maybe you need to do something like this
On error Resume next
' attempt to find and attach to a running instance
Set swApp = GetObject( , "SldWorks.Application") ' note the comma
If swApp Is Nothing Then
' start a new instance
Set swApp = CreateObject( "SldWorks.Application") ' no comma in this
End If
' Attempt to attach to the active doc
Set Part = swApp.ActiveDoc '
If Part Is Nothing Then
' syntax might be completly wrong
Part = swApp.documents.add
End If
On Error Goto 0
Regards,
Peter T
"Maperalia" <Maperalia@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:572B5B18-9A38-4F45-BBAA-5F7553C093F2@xxxxxxxxxxxxxxxx
Peter;
I got help from other source and the y told the following:
Set Part = swApp.ActiveDoc line is returning Nothing, meaning the instance
of SW that your program is hooking to has no open/active document. Change
CreateObject() to GetObject() to hook to an active SW not create a new
instance.
I did ths however, I got the following error message that you may know
what
does is means:
Run-time error '-2147221020(800401e4)':
Automation error
Invalid Syntax
After I click "DEBUG" it is highlighting at the following statement:
Set swApp = GetObject("SldWorks.Application")
Could you please tell me what is the syntax error I have?
"Peter T" wrote:
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" <Maperalia@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:C61522C6-A428-48B7-A5CC-68148437A849@xxxxxxxxxxxxxxxx
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" <Maperalia@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:D9279D5D-C26D-4F02-AE27-8E957A9DA4AA@xxxxxxxxxxxxxxxx
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" <Maperalia@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message
news:B6C6EE15-63C7-47C2-9384-3FA54311B7CE@xxxxxxxxxxxxxxxx
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
- References:
- TabSritp & Multipage
- From: Maperalia
- Re: TabSritp & Multipage
- From: Peter T
- Re: TabSritp & Multipage
- From: Maperalia
- Re: TabSritp & Multipage
- From: Peter T
- Re: TabSritp & Multipage
- From: Maperalia
- Re: TabSritp & Multipage
- From: Peter T
- Re: TabSritp & Multipage
- From: Maperalia
- Re: TabSritp & Multipage
- From: Peter T
- Re: TabSritp & Multipage
- From: Maperalia
- Re: TabSritp & Multipage
- From: Peter T
- Re: TabSritp & Multipage
- From: Maperalia
- Re: TabSritp & Multipage
- From: Peter T
- Re: TabSritp & Multipage
- From: Maperalia
- Re: TabSritp & Multipage
- From: Maperalia
- Re: TabSritp & Multipage
- From: Peter T
- Re: TabSritp & Multipage
- From: Maperalia
- Re: TabSritp & Multipage
- From: Peter T
- TabSritp & Multipage
- Prev by Date: Open my XL File with spacific computer !
- Next by Date: Re: Code to launch VB editor
- Previous by thread: Re: TabSritp & Multipage
- Next by thread: Re: TabSritp & Multipage
- Index(es):
Relevant Pages
|