Component definition script problem?
-
The attached pictured code is a portion of a script. The script run without issue, until I remove or place elsewhere in the script the handrail code, rectangled in red. With the code rectangled in red removed, the script draws the "do intermediate landing" then crashes, the Ruby Console points to the line in yellow.
any ideas what would cause this problem?
-
Some line-numbers would help !
Line #170 is where the error is.
The '.entities' can't apply to 'def_stair' ?
Is 'def_stair' a definition or an instance etc ??
If you remove that red-block of code doesn't it fail at the next 'entities=...' for the intermediate landing ?As an aside... why are you applying materials to back faces ?
Shouldn't you rails be made the right way round - not 'inside-out' ??? -
- I left the line numbers out, because they will change depending on the inclusion or exclusion of the red block of code.
- def_stair is a definition (attached pic) which is located right after the main dialog box and before any drawing routine.
- With the red block of code removed the code does not fail at the intermediate landing, it fails at the next routine which is the drawing of the lower stair drawing, as expressed in the Ruby Console pic.
- back faces: is my mistake, sloppy cutting and pasting of code from a glass material which requires materials expressed for both faces.
- Interestingly, as long as one or the other drawing routines in the red block of code. is in the script, at that place in the script, the script runs flawlessly. ...its very Frustrating
-
You still don't show what happens between creating an empty definition and then trying to add something to it...
If you make a group OR a component-definition and you don't add something to its entities right away then you can find it will auto-erase - because empty definitions do not survive after some operations...
Try making the definition and immediately adding something, e.g.
@cpt=def_stair.entities.add_cpoint(ORIGIN)
You can always use@cpt.erase!
at the end ????? -
If I understand you correctly, are you saying?
- leave one of the drawing routines in the (red block of code) in place.
- followed by an erase of this entity as per your reply.
FYI: My goal ultimately is, to create an option menu where these 2 rail entities (red block of code) will either be all/ON, all/OFF, inside/only, outside/only, via user choice.
I have no problem with an option menu it works! So I had to back track to find the source of the problem, which it turns out to be the railings. Strangely this error occurs only when I'm converting this script into a component definition. (where the user can place the component with the cursor). While the same script without component conversion works flawlessly (stair is placed at origin).
-
You are only ever giving us half the story...
What I said before was:- if you make a new empty definition and then do other things then the system can auto-erase the empty object, so to ensure it's not empty either make it just before you want to add something to its entities, OR add a cpoint to its entities immediately after you make it at the start, that way it's not empty and no longer prone to disappear mysteriously - I think that is what's happening when you try to add something later and it says that '.entities' is not a method that can be used by 'Nil' - therefore the 'definition reference' is not valid or initially set properly [I haven't seen all of the code!]...
Can you perhaps set out [in words] the structure of the 'parts' of your tool, so that we can see where you need to think about making the code 'robust'...
-
@tig said:
You are only ever giving us half the story...
Sorry about that! I clearly had some difficulty thinking outside the box. The empty definition did not work in this case, so I added a dummy line definition entity and erased it.
#----Do dummy line entities = def_stair.entities # def line = entities.add_line (@p8, @p7) entities.erase_entities line
all is well now, thanks!
Advertisement