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

macro with userform for automatic creation of a prism starting from surface and edge

Andrea Amedei

Guest
Good morning.

It's a few days that I'm banging my head without coming to the head. Since I often need to perform the solid feature that you see in the image below on various holes, I was thinking of creating a macro that automated this process.
the solid feature to build is a "prism" that has as a basic sketch the projection of a hole and a larger circle that has a diameter n times greater than that projected (n parameter to set). extrusion height is also a parameter.1679646998897.pngto do this, I created a userform that you can see in the figure below. the user must use the 3 buttons in sequence (ground selection, select hole edge, create solid) and the two text boxes of the d/d ratio and the profile extrusion height.1679647499974.pngI admit I know quite well the vba programming on excel, but they are really at first with catia. at the moment what I did is the following:
"select surface" buttonprivate sub select_surface_button_click_click()
dim myselection
dim myarray(0) as face
dim strreturn as string
dim part1 as part
dim partdocument1 as partdocument
dim myhybridbodies as hybridbodies

set myselection = catia.activedocument.selection
myselection.clear
me.hide

strreturn = myselection.selectelement2(array("face"), "select a face:", false)
if strreturn = "normal" then
'redim preserve myarray(ubound(myarray) + 1)
set myarray(ubound(myarray)) = myselection.item2(1).value
end if
textbox1.text = myarray(0).name
me.show
end sub

button "select edge hole"private sub select_edge_button_click_click()
dim myselection
dim myarray(0) as edge
dim strreturn as string
dim part1 as part
dim partdocument1 as partdocument

set myselection = catia.activedocument.selection
myselection.clear
me.hide

strreturn = myselection.selectelement2(array("edge"), "select a edge:", false)
if strreturn = "normal" then
'redim preserve myarray(ubound(myarray) + 1)
set myarray(ubound(myarray)) = myselection.item2(1).value
end if
textbox2.text = myarray(0).name
me.show
end sub
at this point, in the longer text boxes the name(?) of the selected surface and edge appears. pressing "crea solid" I would like the software to build:
1. a sketch plan on the selected surface (using the name in the userform? )
2. from the edge of the selected hole derives the diameter and its center
3. takes the edge of the hole and projects it on that floor
4. creates a new circle with the same center of the projected edge and diameter d=n*d
5. comes out of the sketch
6. extrude height set in userform
7. uncheck everything and cleans all userform for a new operation

I hope someone can help me, even with the macro record I can't understand how the program works.

greetings,

Andrea
 
I can't help you in programming, but to achieve prism as you wish, one of the possible ways is this:

1) you have surface
2) you have the diameter (in this case higher than the surface)
3) revenues the center of the diameter (features point/type of point/circle. ..centre
4) create the sketch using as floor the surface
5) inside the sketch project the circle (menu/insert/operation/geometria 3d/project elements 3d
6) put a constraint to the diameter (it will give you a reference quota in parentheses)
7) Projects in construction mode the point
8) use the point to build the outer diameter
9) impose the constraint of the diameter and change the formula (right/modify the formula, select the quota of the constraint and multiply for value n
10) get out of the sketch and generate prisma

from the formulas revenues the names necessary to set the programming

Let me know.

Hi.
 

Attachments

thanks gianni55 of the answer.

the algorithm I want to create follows just your steps (more or less).

what I need however are the commands, firstly how to open the sketch editor right on the surface I selected (of which I have the name).

later, to build the prism I can use the "record macro" function to understand what commands to use.

Thank you.
 
thanks gianni55 of the answer.

the algorithm I want to create follows just your steps (more or less).

what I need however are the commands, firstly how to open the sketch editor right on the surface I selected (of which I have the name).

later, to build the prism I can use the "record macro" function to understand what commands to use.

Thank you.
Bye-bye.
to open the sketch editor you have to be in part design environment and obviously have on the screen all the icons to be able to choose that of the sketch i.e. a sheet with a pencil, after the selection the system waits for the selection of the geometry.
but if you don't have a cat's familiarity because you even want to create a macro?
 
Hi, gianni, I probably didn't explain well. I can use caia and therefore also make that simple prism.

the macro serves to automate the procedure and make it all faster, as I do not have to do it on a hole only but on multiple holes, in even different surfaces.

That's why I told you the algorithm follows your steps, but I need it in the form of vba commands. how to do it on every single hole is me, alas, even too light xd
 
No problem. :

I don’t know her, can you tell me some links to study the subject?

Thank you.
 
quoted by catia guide:
a group copy consists of a series of features (geographical elements, formulas, constraints and so on) that are grouped to be used in a different context. they can be completely redefined when they are glued.
group copy captures the design intent and know-how of the designer, allowing for greater reuse and efficiency.

practically perform a series of modeling operations that then reuse by simply changing some data of impt
 

Forum statistics

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

Members online

No members online now.
Back
Top