• This forum is the machine-generated translation of www.cad3d.it/forum1 - the Italian design community. Several terms are not translated correctly.

limiti macro solidworks

  • Thread starter Thread starter lucadileta
  • Start date Start date
as regards point 1:

- in the macro that I had laid down I avoided replacing the component, it is not necessary, in fact for each selected component I open it,
I perform offset and body deletion work and then I perform a "Save with Name" using the bee call
boolstatus = swpartmodel.extension.saveas(newfile, 0, 1, nothing, longstatus, longwarnings)

this save automatically renames the file in use, leaving the old file in the directory, not having saved it before the save by name,
the changes are eliminated, getting the same result you were trying to do.
the axieme takes the new references, just remember to save it after the macro has finished.

by point 2:

selcount = swselmgr.getselectedobjectcount()
if selcount
dim swselobj as object
for z = 1 to swselmgr.getselectedobjectcount()
set swselobj = swselmgr.getselectedobject5(z)
set swcomp = swselmgr.getselectedobjectscomponent2(z)
set swcompmodel = swcomp.getmodeldoc

.... now continue with the code, obtaining the path of the component, open it as a file of part, process the body, and save by name
....


end if


I set your way because I know you want to complete it yourself, if you need it in the next steps ask yourself, never give up

Good day
Thank you so much jenuary, you're a myth! I'll be back tonight and see where I'm coming.
 
as regards point 1:

- in the macro that I had laid down I avoided replacing the component, it is not necessary, in fact for each component. . .
View attachment MAcro_SW.ziphi jenuary, I went a little forward with the macro and I got to integrate your code. Of course it doesn't work well :confused:

the part file is opened, your subroutine is executed but unfortunately does not save the part with the new name and at the time of closing the file closes the axieme and not the open part... I think the mistake I committed him to instil the item part, I messed up with the names. as second thing I wanted to ask you if it was possible to perform operations on the background part without opening it in the window so as not to load the work of the pc uselessly, do you think it is feasible?

I would be infinitely grateful if you could take a look at the macro that is in the zip file, the code is a little messed up but you should be able to read it. Just tell me where the error is, it would be enough, so I'll take it off and correct it.

p.s. in the file you also find my set with which I perform the macro test.

thanks as usual of your support and good evening! :
 
View attachment 46437hi jenuary, I went a little forward with the macro and I got to integrate your code. Of course it doesn't work well :confused:

the part file is opened, your subroutine is executed but unfortunately does not save the part with the new name and at the time of closing the file closes the axieme and not the open part... I think the mistake I committed him to instil the item part, I messed up with the names. as second thing I wanted to ask you if it was possible to perform operations on the background part without opening it in the window so as not to load the work of the pc uselessly, do you think it is feasible?

I would be infinitely grateful if you could take a look at the macro that is in the zip file, the code is a little messed up but you should be able to read it. Just tell me where the error is, it would be enough, so I'll take it off and correct it.

p.s. in the file you also find my set with which I perform the macro test.

thanks as usual of your support and good evening! :
Good morning lucadileta,
I looked at the macro and noticed that the offset function and body deletion was not performed in addition to the rescue problem.
The hippo was precisely in the instance of the part object, which was actually instigated right, but then you did not use it because you passed into the various successive swmodel lines (which was the modeldoc2 of the axieme) instead of swpartmodel (which refers to the open part that serves you).
I corrected the macro by commenting on the lines I corrected so see where I intervened.

for the question of not seeing the files of the parties opening, it is not always feasible, in our case it is not because the call
swapp.activatedoc2

activate the document and if you don't do it you can't create the swpartmodel instance and add feature in the tree, in other cases you can use the call

swapp.documentvisible false, swdocumenttypes_e.swdocpart (not to see that the part opens)
and then after closing the document starts the restoration
swapp.documentvisible true, swdocumenttypes_e.swdocpart (restore display)

I still entered two calls not to see the graphics that work and the inclusion of the features in the featuremanager

swmodel.setdisplaywhenadded (false)
swmodel.featuremanager.enablefeaturetree = false

that makes the execution faster, later, at the end of the macro should be restored to true
all things you can go to see then in the bee manual

Alternatively, you can run the steps directly from inside the axieme by changing the component and then saving it by name,
the result is the same, turn off the graphics as I wrote you above and then eventually reactive.

I open a brief bracket about the object "swapp", because I saw that you replaced the line with this:

set swapp = createobject("sldworks.application") --> this creates a solidworks object (duplicated)
while
set swapp = application.sldworks --> connects directly to active solidworks (it is the potential of integrated vba)

in macros I recommend you to use set swapp = application.sldworks, you have no reason to create another parallel solidworks object.
in case you create stand alone programs (.exe) then you are obliged to create a parallel solidworks object, and that's why macros (vba) are much more likely than .exe programs.

I hope I've been clear in the explanation, it's not easy to explain to others these things by writing, if you have questions about it, ask yourself.
 

Attachments

Good morning lucadileta,
I looked at the macro and noticed that the offset function and body deletion was not performed in addition to the rescue problem.
The hippo was precisely in the instance of the part object, which was actually instigated right, but then you did not use it because you passed into the various successive swmodel lines (which was the modeldoc2 of the axieme) instead of swpartmodel (which refers to the open part that serves you).
I corrected the macro by commenting on the lines I corrected so see where I intervened.

for the question of not seeing the files of the parties opening, it is not always feasible, in our case it is not because the call
swapp.activatedoc2

activate the document and if you don't do it you can't create the swpartmodel instance and add feature in the tree, in other cases you can use the call

swapp.documentvisible false, swdocumenttypes_e.swdocpart (not to see that the part opens)
and then after closing the document starts the restoration
swapp.documentvisible true, swdocumenttypes_e.swdocpart (restore display)

I still entered two calls not to see the graphics that work and the inclusion of the features in the featuremanager

swmodel.setdisplaywhenadded (false)
swmodel.featuremanager.enablefeaturetree = false

that makes the execution faster, later, at the end of the macro should be restored to true
all things you can go to see then in the bee manual

Alternatively, you can run the steps directly from inside the axieme by changing the component and then saving it by name,
the result is the same, turn off the graphics as I wrote you above and then eventually reactive.

I open a brief bracket about the object "swapp", because I saw that you replaced the line with this:

set swapp = createobject("sldworks.application") --> this creates a solidworks object (duplicated)
while
set swapp = application.sldworks --> connects directly to active solidworks (it is the potential of integrated vba)

in macros I recommend you to use set swapp = application.sldworks, you have no reason to create another parallel solidworks object.
in case you create stand alone programs (.exe) then you are obliged to create a parallel solidworks object, and that's why macros (vba) are much more likely than .exe programs.

I hope I've been clear in the explanation, it's not easy to explain to others these things by writing, if you have questions about it, ask yourself.
Good morning jenaury:) you were very clear on the other hand, holy now! Thank you so much for your support, I'll see your corrections tonight and I'll study them well. I would instead ask you a question since you are programmer of .net. asking my fellow programmers told me that visual basic.net is practically falling, at least in the web application programming, piano in disuse while languages like java and c# are always on the crest of the wave. now as I intend, after bazzicato with java at university, to learn how you owe a programming language to objects with the main purpose of implementing gui then interface me with various programs such as matlab, sw, ansys etc. always in microsoft environment (both externally through dll, that internally creating for example for sw featureas ad hoc) you, made these premises and considering your experience, what do I recommend?

thanks as always infinitely and good day!
 
It's a good question.
.net is too present in applications generally, dropping it seems a little premature in my opinion.
at the bottom .net is the evolution of the vb6 that the year made to die in the passage to 64 bit, but in reality it is melted inside the .net, are the foundations of windows.
Of course, using a multi-platform development software is ideal as a whole, I see that it is much more widespread .net, in fact I learned that only for this reason, in other areas maybe it is preferable to develop in java.
with the c# it is said that you can do more, but we talk about programs pushed where I do not arrive, and it is more complicated than the .net, which has more shortcuts among other things.

There is no answer to me, the ideal would be to know them both....(already it is hard to know one).

if we only talk about solidworks, I think the best thing is the implementation by addin (dll), much faster and more flexible than stand alone programs and macros, since you use the framework (savebackground is developed in this way).

soon
 
It's a good question.
.net is too present in applications generally, dropping it seems a little premature in my opinion.
at the bottom .net is the evolution of the vb6 that the year made to die in the passage to 64 bit, but in reality it is melted inside the .net, are the foundations of windows.
Of course, using a multi-platform development software is ideal as a whole, I see that it is much more widespread .net, in fact I learned that only for this reason, in other areas maybe it is preferable to develop in java.
with the c# it is said that you can do more, but we talk about programs pushed where I do not arrive, and it is more complicated than the .net, which has more shortcuts among other things.

There is no answer to me, the ideal would be to know them both....(already it is hard to know one).

if we only talk about solidworks, I think the best thing is the implementation by addin (dll), much faster and more flexible than stand alone programs and macros, since you use the framework (savebackground is developed in this way).

soon
Thanks for the info jeanuary! :) at this point I think I'm going to c# even if I'm not 100% sure yet
 
Good morning lucadileta,
I looked at the macro and noticed that the offset function and body deletion was not performed in addition to the rescue problem.
The hippo was precisely in the instance of the part object, which was actually instigated right, but then you did not use it because you passed into the various successive swmodel lines (which was the modeldoc2 of the axieme) instead of swpartmodel (which refers to the open part that serves you).
I corrected the macro by commenting on the lines I corrected so see where I intervened.

for the question of not seeing the files of the parties opening, it is not always feasible, in our case it is not because the call
swapp.activatedoc2

activate the document and if you don't do it you can't create the swpartmodel instance and add feature in the tree, in other cases you can use the call

swapp.documentvisible false, swdocumenttypes_e.swdocpart (not to see that the part opens)
and then after closing the document starts the restoration
swapp.documentvisible true, swdocumenttypes_e.swdocpart (restore display)

I still entered two calls not to see the graphics that work and the inclusion of the features in the featuremanager

swmodel.setdisplaywhenadded (false)
swmodel.featuremanager.enablefeaturetree = false

that makes the execution faster, later, at the end of the macro should be restored to true
all things you can go to see then in the bee manual

Alternatively, you can run the steps directly from inside the axieme by changing the component and then saving it by name,
the result is the same, turn off the graphics as I wrote you above and then eventually reactive.

I open a brief bracket about the object "swapp", because I saw that you replaced the line with this:

set swapp = createobject("sldworks.application") --> this creates a solidworks object (duplicated)
while
set swapp = application.sldworks --> connects directly to active solidworks (it is the potential of integrated vba)

in macros I recommend you to use set swapp = application.sldworks, you have no reason to create another parallel solidworks object.
in case you create stand alone programs (.exe) then you are obliged to create a parallel solidworks object, and that's why macros (vba) are much more likely than .exe programs.

I hope I've been clear in the explanation, it's not easy to explain to others these things by writing, if you have questions about it, ask yourself.
hi jenuary, I finally had a moment of time to look how you owe the macro, all perfect only that now I would like to edit the part in the axieme and not to let him open a own window therefore I added the following:

set swpartmodel = swselobj
swmodel.editpart()

instead of:

set swpartmodel = swapp.activatedoc2(selcomppath, true, nretval)': debug.assert 0 = nretval

where swselobj was so instigated:

set swselobj = swselmgr.getselectedobject5(z)

If I understand well getselectedobject5 should create a pointer to the selected object therefore I do not understand where the problem is :confused:

thanks endless as always of your availability and good weekend! :
 
hi jenuary, I finally had a moment of time to look how you owe the macro, all perfect only that now I would like to edit the part in the axieme and not to let him open a own window therefore I added the following:

set swpartmodel = swselobj
swmodel.editpart()

instead of:

set swpartmodel = swapp.activatedoc2(selcomppath, true, nretval)': debug.assert 0 = nretval

where swselobj was so instigated:

set swselobj = swselmgr.getselectedobject5(z)

If I understand well getselectedobject5 should create a pointer to the selected object therefore I do not understand where the problem is :confused:

thanks endless as always of your availability and good weekend! :
Hi.
in the macro that I attach the following steps:
- cycle selections, echo components and store them in an array of components
- cycle the array and for each component it is published, I create the surface offset and gate the body
- except by name the component
- I exit from the change of the component

Try it and let me know
 

Attachments

Hi.
in the macro that I attach the following steps:
- cycle selections, echo components and store them in an array of components
- cycle the array and for each component it is published, I create the surface offset and gate the body
- except by name the component
- I exit from the change of the component

Try it and let me know
hi jenuary I tried you macro and obviously function :), I also understood the steps you do and follow what is not clear to me:

My first difficulty is to create pointers to the object I care about and I certainly make mistakes in interpretation of the code, I explain better.

Once the object is entered together in the working window, I do not understand how to enter the sublevel in which all the parts are contained in the aid concerned.
Code:
set swapp = application.sldworks         ' accedo a sw  
set swmodel = swapp.activedoc           ' accedo al documento attivo, in questo caso l'assieme
Now the next line to me seems totally unnecessary :confused:
Code:
set swassy = swmodel
since both swmodel and swassy point to the same class

now once you select the parts that interest me coming to the point of instigation the selected items by
Code:
swselobj = swselmgr.getselectedobject5(z)
at this point I already had to point to the object "selected part" and would simply write to me
Code:
swselobj .editpart
that is wrong.

what I've noticed, or at least I feel like I understand, is that you

Code:
set swcomp = swselmgr.getselectedobjectscomponent2(z)
call the component not the item part
Code:
swmodel.clearselection2 true
I don't understand.

and finally it seems to me that you activate the "modeldoc" of the selected component sena then use it... :confused:
Code:
set swcompmodel = swcomp.getmodeldoc
swcomp.select false ' I don't understand the use
swassy.editpart here swassy to what point? ?
swmodel.clearselection2 true 'I don't understand use
I apologize for the tide of fregnacce that I definitely wrote, I would be grateful if I could help me clarify these steps. I am sure but I have the feeling, certainly wrong, that they make a lot more complex passages than necessary...:confused:
 
Hello, luca.
First point:
while set swmodel = swapp.activedoc gives you access to the active document, regardless of whether it is a set, table or part

swassy set = swmodel from access to the exclusive library of the assemblies, in fact it is declared
dim swassy as sldworks.assemblydoc,
while swmodel from access to the declared modeldoc2 library
dim part as sldworks.modeldoc2 of the generic document.

we go to the next point:
swselobj = swselmgr.getselectedobject5(z)

in this case you have assigned to an object variable the content of the pointer to the value index z,
indifferently that the content is a component, a edge, a sketch, a surface etc.
the call ".editpart" is part of the component library, so you have to pass the component to edit it and to do so you have to
create the component object by passing the object to the z index

set swcomp = swselmgr.getselectedobjectscomponent2(z)

now, however, since nothing is more selected in the graphics area, you must select your component to edit it
then swcomp.select false where false serves not to add it to the list of other active selections.

next point:
swmodel.clearselection2 true
eliminates active selections

next point:
Imagine that the current document is a box and for accessing it you have to open it, this first step gives it to you
modeldoc2 setting the object set swmodel = swapp.activedoc (active document)
therefore the swmodel is not the component but the active part, in order to have access to the component, which in turn is a box contained in the box of the active document, you have to access it through the modeldoc2 of the component, that is why it is accessed through

set swcompmodel = swcomp.getmodeldoc

next point:
to exit from the component modification, without changing other components or under axiemi, then take you to the first level of the tree, use

Swassy.editpart

which is a joint command and is part of the document call library together; the same thing happens when you want to cycle the bodies contained in the part, to do so you have to pass a document part if you want to have access to the body.

next point:
this call eliminates all active selections.
swmodel.clearselection2

ps.: you will excuse me for the terms used that in part are technical terms related to programming, others are rough terms I used to explain, but it is not easy, sometimes it would be easier to make a pattern in a sheet of paper.
for those who are trying to approach programming to objects, I recommend to put down in a sheet of paper a ladder of the various steps that must perform the macro, this helps a lot in creating the architecture of the macro, in time and with the experience you will see that it will no longer be necessary.
allego hoping that you can use the set of objects in the solidworks bees manual, imagine that each box is a box and to get there you have to pass through the previous box (every box has a library of information (free is just a technical term))

Hi.
 

Attachments

  • SolidWorks-Basic-Object-Model.webp
    SolidWorks-Basic-Object-Model.webp
    24.5 KB · Views: 7
Hello, luca.
First point:
while set swmodel = swapp.activedoc gives you access to the active document, regardless of whether it is a set, table or part

swassy set = swmodel from access to the exclusive library of the assemblies, in fact it is declared
dim swassy as sldworks.assemblydoc,
while swmodel from access to the declared modeldoc2 library
dim part as sldworks.modeldoc2 of the generic document.

we go to the next point:
swselobj = swselmgr.getselectedobject5(z)

in this case you have assigned to an object variable the content of the pointer to the value index z,
indifferently that the content is a component, a edge, a sketch, a surface etc.
the call ".editpart" is part of the component library, so you have to pass the component to edit it and to do so you have to
create the component object by passing the object to the z index

set swcomp = swselmgr.getselectedobjectscomponent2(z)

now, however, since nothing is more selected in the graphics area, you must select your component to edit it
then swcomp.select false where false serves not to add it to the list of other active selections.

next point:
swmodel.clearselection2 true
eliminates active selections

next point:
Imagine that the current document is a box and for accessing it you have to open it, this first step gives it to you
modeldoc2 setting the object set swmodel = swapp.activedoc (active document)
therefore the swmodel is not the component but the active part, in order to have access to the component, which in turn is a box contained in the box of the active document, you have to access it through the modeldoc2 of the component, that is why it is accessed through

set swcompmodel = swcomp.getmodeldoc

next point:
to exit from the component modification, without changing other components or under axiemi, then take you to the first level of the tree, use

Swassy.editpart

which is a joint command and is part of the document call library together; the same thing happens when you want to cycle the bodies contained in the part, to do so you have to pass a document part if you want to have access to the body.

next point:
this call eliminates all active selections.
swmodel.clearselection2

ps.: you will excuse me for the terms used that in part are technical terms related to programming, others are rough terms I used to explain, but it is not easy, sometimes it would be easier to make a pattern in a sheet of paper.
for those who are trying to approach programming to objects, I recommend to put down in a sheet of paper a ladder of the various steps that must perform the macro, this helps a lot in creating the architecture of the macro, in time and with the experience you will see that it will no longer be necessary.
allego hoping that you can use the set of objects in the solidworks bees manual, imagine that each box is a box and to get there you have to pass through the previous box (every box has a library of information (free is just a technical term))

Hi.
hi jenuary, first of all I don't know how to thank you for your availability, :) you're just the top. about how you explained to me as soon as I have a second of time I study it for good. The image you posted to me is really exhaustive and that was exactly what I needed. having programmed graphical interfaces with programming javas to objects a little know, what I missed was just the encapsulation showing the image you posted. Now it is all much clearer to me:). Just one thing, is the manual sw bees what I find in the help? Thanks again jenuary and good evening! as soon as I finished the macro place and comment well so maybe it will be useful to some other :-)
 
Hello, luca.
you the manual is what you find inside the "?" online bee guide
Thank you so much as always jenuary, I didn't have any xd case. As soon as I have a moment of breath I'll take you on the macro. Good evening!
 

Forum statistics

Threads
44,997
Messages
339,767
Members
4
Latest member
ibt

Members online

No members online now.
Back
Top