Create component with a subroutine question
-
Hi,
What I want to do is to create a component like a table. I use one same subroutine to create the four legs and the top.
I declared a component definition in the Main like this:
$new_comp_def=Sketchup.active_model.definitions.add("MyComp")
then try to add some face entitites in a subroutine to it like this:
points ...
face=$new_comp_def.entities.add_face(points)
face.pushpull(height)The error I got is some nil faces which can't be pushpulled. It seems the global virable $new_comp_def has no efect. I can't save the entities into it. Sometimes the error message says I was referencing a deleted entity.
Are these faces deleted when the subroutine finished?
Thanks
-
Could you post the exact error?
I'm wondering though, if the points you feed
.add_face
doesn't make up a face. Do a check if the valueface
has after.add_face
, if it'snil
, then the method failed, which leads.pushpull
to fail because you are trying to pushpull anil
value.Btw, I'd recommend that you don't use global variables. It could interfere with other scripts. Encapsulate your script in a Module or Class and use Module/Class variables instead.
-
Made some changes and works now.
It seems I have to declare one definition,add entities and place the component. After that, declare anonther component definition,....
If I declare a few definitions at the same time, when the subroutine is called for the second component, it will report the entities has been deleted.
-
If you are creating them all like this:
$bad_global_variable_new_group = entities.add_group $bad_global_variable_new_group = entities.add_group $bad_global_variable_new_group = entities.add_group $bad_global_variable_new_group = entities.add_group
The variable only points to the last one. The first 3 will be lost.
Advertisement