Inputbox control with while loop
-
At least I think so !
I have this code and it SHOULD show 2 stacked cylinders - see line 79 and 80 BUT...
I think the pushpull is going in THE WRONG direction - OK, I can then just change the 2.mm to -2.mm in line 80, but with the normal vector [0,0,1] it SHOULD be 2.mm - right ?
OK - try this: Change the 12.7.mm in line 79 to 12.73.mm - not 12.71.mm or 12.72.mm - abra ca dabra - now the pushpull is going in the same direction as the normal vector - the RIGHT direction - agree ?
What is wrong ?
require 'sketchup.rb' module KSOR UI.menu("PlugIns").add_item("Kileremskive"){KSOR;;Polley.new()} class Polley # store bogstaver evt. med _ er en CONST MINDIAP = 40.mm MINDIAA = 10.mm MINKRVD = 20.mm MINKRVB = 15.mm Sketchup.send_action("showRubyPanel;") def initialize() @model = Sketchup.active_model @entities = @model.active_entities self.draw_pulley() end def draw_pulley() # secure at least default MINIMUM values @diaP = MINDIAP if not @diaP or (@diaP < MINDIAP) @diaA = MINDIAA if not @diaA or (@diaA < MINDIAA) @krvD = MINKRVD if not @krvD or (@krvD < MINKRVD) @krvB = MINKRVB if not @krvB or (@krvB < MINKRVB) return nil unless self.input_dialog() self.draw_beltProfile() self.set_beltProfileOnWheel() self.pull_pulley() self.pull_krave() end def input_dialog() prompts = ["Skivediameter (mm) ;", "Akseldiameter (mm) ;", "Kravediameter (mm) ;", "Kravebredde (mm) ;"] values = [@diaP, @diaA, @krvD, @krvB] results = inputbox(prompts, values, "Specifikationer") return nil if not results diaP, diaA, krvD, krvB = results if (diaP < MINDIAP) || (diaA < MINDIAA) || (krvD < MINKRVD) || (krvB<MINKRVB) UI.messagebox("Mindsteværdi er genindsat - de(n) SKAL overholdes !", MB_OK) self.draw_pulley() return nil else @diaP, @diaA, @krvD, @krvB = results return true end end def draw_beltProfile() # Her laves en profil, som svarer til en kilerem # med YDERSIDEN en halv diameter ude af X-aksen pt1 = [0 + (@diaP.to_f/2) - 13.8.mm, 4.22.mm, 0] pt2 = [@diaP.to_f/2, 0, 0] pt3 = [@diaP.to_f/2, 12.7.mm, 0] pt4 = [0 + (@diaP.to_f/2) - 13.8.mm, 8.48.mm, 0] # profilfladen laves @beltProfile = @entities.add_face(pt1, pt2, pt3, pt4) end def set_beltProfileOnWheel() # Skive laves @periferi = @entities.add_circle([0,0,0], [0,0,1],@diaP.to_f/2, 48) # rotate beltProfile 90° tr = Geom;;Transformation.rotation([13.8.mm,0,0], [1,0,0], 90.degrees) @entities.transform_entities(tr, @beltProfile) # gruppen exploderes for at lave FollowMe og findes så ikke mere @beltProfile.followme(@periferi) @periferi=nil end def pull_pulley() # Nu skal siderne på skiven laves 2 mm på hver side opSideFlade = @entities.add_face(@entities.add_circle([0,0,12.7.mm], [0,0,1], @diaP.to_f/2, 48)) # HERE change to 12.73.mm opSideFlade.pushpull(2.mm) =begin nedSidePeriferi = @entities.add_circle([0,0,0], [0,0,1], @diaP.to_f/2, 48) nedSideFlade = @entities.add_face(nedSidePeriferi) nedSideFlade.pushpull(-2.mm) =end cleanUp end def cleanUp() # En cylinderflade fjernes, så der åbnes ind til remprofilen end def pull_krave() # En krave til nippel skruer laves efter angivne dimensioner # og der skal laves hul til akslen med den givne diameter end end #class end # module
-
A few points Keld.
Please use specific and informative topic titles, so later on people can find topics (using search,) for issues they need help with.
Titles like; "this syntax is driven me MAD !!!!!!" and "Spooky things going on here !!!!!" are worthless.
(This is called proper forum etiquette.)Better titles would be:
"Inputbox control with while loop" for the topic called: "this syntax is driven me MAD !!!!!!"
and
"Push Pull direction?" for THIS topic: "Spooky things going on here !!!!!"*******ONLY you can change those titles because you are the original poster (OP.)
-
Agree with Dan about the 'Titling' being more helpful - and likely to attract more help from others too...
A few pointers about face making and pushpull.
When you make a face the order of the points determine its 'normal'.
EXCEPT if the face is flat on the ground-plane [z=0] then it ALWAYS faces down [normal=[0,0,-1]]
So if you make a face like this you can useface.reverse!
to make it face up - if that's what you need...Using
face.pushpull(dist)
does a pushpull in the direction of theface.normal
, therefore determining that before doing the pushpull is done is needed IF the face might not be oriented as desired...face.normal.z<0
tells you it's facing down,face.normal.z>0
it's up andface.normal.z==0
it's vertical etc etc...
You can either useface.reverse!
to flip it and then leave the pushpull 'dist' as it is, or set up two cases for the possible normal direction and thereby use +/-ve values for 'dist'...When you post code it would help if you explain the context and post the relevant section of code - it's a pain to trawl through many lines of code as you've just posted to find the few lines or the method that you are having difficulty with - I have scripts 4000 lines long ! you might one day too...
-
Your code looks so much better.
The forum does not handle tabs very well. (The blocks are not lining up correctly.)
In Notepad++,
"Settings" (menu) > "Preferences" (dialog) > "Language Manu/Tab Settings" (page)
In the "Tab Settings" group (on the right of the page,).. if you hilight "ruby" in the list:
and check "replace by space"We will be able to read your code blocks much easier.
But.. If you do not want to actually change your files (that you work with,) .. then instead:
"Edit" (menu) > "Select All" or CTRL+A
"Edit" (menu) > "Copy" or CTRL+C
Click the "New" file button, and paste in the code.
Then click the find button (Binoculars)
On the "Find" dialog, switch to the "Replace" (page)
In the "Find what:" box type: \t
("\t" is the escape chars for a TAB.)
In the "Replace with:" box type spaces (2 or 4, whatever you wish.)
In the "Search Mode" group at the lower-left, select "Extended {...}", or press ALT+XThen click the "Replace All" button.
If everything worked OK... close the Find/Replace dialog.
Select All text again (if you need to.)
"Edit" (menu) > "Copy" or CTRL+C
(so the text with spaces instead of tabs is on clipboard,)
Then switch to your browser, where you should already have your SketchUcation "POST A REPLY" form ready,
click between [ code ] [ /code ] tags (or click the [ Code ] button on the edit post toolbar, which will paste in the tags, and put the cursor between them, for you.)
CTRL+V (to paste in the code's text.)When you go back Notepad++, you just close the "New" tab, and say "No" to save.
ADD: I DO think that Notepad++ can run macros. So you might check the NPP docs, on how to write a "replace all tabs with 4 spaces" macro.
-
Yes, you'r SO right !
About the npp++ and TABs I can only choose Ruby and the "Use standard setting" about the TABs - the "Use spaces is disabled"
I'll try to let my headlines TELL about the problem in the post
BUT it IS DRIVING ME MAD !!!!!!!!!! )
-
You must uncheck "Use default value" first ...
ADD: OR.. you can hilight "[Default]" at the top of the list, and change the default to what you want most of your code to do with TAB characters.
Then change the specific few languages that you want to be different (ie: Python, Javascript, Java, HTML and CSS, all use 4 space tabs, instead of 2. Likely all the C language family as well. C, C++ and C#.)
Advertisement