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_facedoesn't make up a face. Do a check if the valuefacehas after.add_face, if it'snil, then the method failed, which leads.pushpullto fail because you are trying to pushpull anilvalue.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.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement