kruszynski

Moderatorzy
  • Postów

    1 427
  • Dołączył

  • Ostatnia wizyta

  • Wygrane w rankingu

    83

Odpowiedzi opublikowane przez kruszynski

  1. Tak na szybko to mogłoby to być takie coś:

    (setq R (getdist "podaj rozstaw"))
    (setq dim (vlax-ename->vla-object (car(entsel "Wybierz wymiar"))))
    (setq A (vlax-get-property dim 'Measurement) )
    (setq X (/ A R))
    (vlax-put-property dim 'TextOverride (strcat "#8 co " (rtos X) " cm"))
    • Nie ma jeszcze zaokrąglenia.
    • Nie wiem czy zadziała w Arcadi. w ZWCAD działa.
  2. Taki skrypt mógłby wyglądać np tak:

    (defun C:SzykManualny (  / element odleglosc bazowy kierunek 
    							Koniec licznik
    							kopiuj
    	*error* )	(defun *error* ( msg / ) 
    		(if (not (null msg ) )	(progn (princ "\nC:SzykManualny:*error*: " ) (princ msg ) (princ "\n")	) )
    	)
    	(setq Koniec ""
    			licznik 1 )
    	
    	(defun kopiuj (  / v1
    		*error* )	(defun *error* ( msg / ) 
    			(if (not (null msg ) )	(progn (princ "\nkopiuj:*error*: " ) (princ msg ) (princ "\n")	) )
    		)
    		( setq v1 ( Vector:Normalize ( Vector: kierunek bazowy  ) ) ) 
    		( setq v  ( Vector:XScalar v1 (* odleglosc licznik ) ) )
    		( setq clone (vlax-invoke-method element 'Copy) )
    		( setq px (Vector+ bazowy v ))
    		(vlax-invoke-method clone 'Move (vlax-3d-point bazowy) (vlax-3d-point px)  )
    		(setq licznik (1+ licznik)) 
    	)
    	
    	
    	(setq element (SelSet:Entsel "Wskaż element" nil))
    		(if (null element) (*error* nil) )
    	(setq odleglosc (ZWCAD:GetDist "Podaj odległość" poprzedniaOdleglosc))
    		(if (null odleglosc) (*error* nil) )
    	(setq bazowy (ZWCAD:Getpoint "Wskaż punkt bazowy" nil nil ) )
    		(if (null bazowy) (*error* nil) )
    	(setq kierunek (ZWCAD:Getpoint "Wskaż kierunek" bazowy nil ) )
    		(if (null kierunek) (*error* nil) )
    	(while	(equal Koniec "")
    		( kopiuj )
    		(setq Koniec ( ZWCAD:GetString "Czy wstawić kolejny" "" ) )
    	)
    	
    	(setq poprzedniaOdleglosc odleglosc)
    	(princ)
    )
    
    (defun Vector: ( A B /
      *error* ) 	(defun *error* ( msg / ) 
    		(if (not (null msg ) )	(progn (princ "\nVector::*error*: " ) (princ msg ) (princ "\n")	) )
    	)       
    	(list 
    		(- (car A) (car B ) )
    		(- (cadr A) (cadr B ) )
    		(- (caddr A) (caddr B ) )
    	)
    )
    
    (defun Vector:Length (vec / s 
     *error* ) 	(defun *error* ( msg / ) 
    		(if (not (null msg ) )	(progn (princ "\nVector:Length:*error*: " ) (princ msg ) (princ "\n")	) )
    	)       
    	(setq s (+ (* (car vec) (car vec) ) (* (cadr vec) (cadr vec) ) (* (caddr vec) (caddr vec) )))
    	(if (< s 0.0000000000001 ) 0.0 (sqrt s ))
    ) 
    (defun Vector:Normalize (v / len 
    	*error* ) 	(defun *error* ( msg / ) 
    		(if (not (null msg ) )	(progn (princ "\nVector:Normalize:*error*: " ) (princ msg ) (princ "\n")	) )
    	)       
    	(setq len (Vector:Length v) )
    	(if (< len 0.00000001)	
    		(list 0.0 0.0 0.0 )
    		(progn
    			(list 	(/ (car v ) len)
    					(/ (cadr v ) len)
    					(/ (caddr v ) len)	
    			)
    		)
    	)
    )
    
    
    (defun Vector:XScalar (v s / 
     *error* ) 	(defun *error* ( msg / ) 
    		(if (not (null msg ) )	(progn (princ "\nVector:XScalar :*error*: " ) (princ msg ) (princ "\n")	) )
    	)      
    	(mapcar '(lambda (x) (* x s) ) v )
    )
    
    (defun Vector+ (A B / 
     *error* ) 	(defun *error* ( msg / ) 
    		(if (not (null msg ) )	(progn (princ "\n Vector+ : *error*: " ) (princ msg ) (princ "\n")	) )
    	)                  
    	(if (null A) (setq A (list 0.0 0.0 0.0  ) ))
    	(if (null B) (setq B (list 0.0 0.0 0.0  ) ))
    	(list 
    		(+ (car A ) (car B) )
    		(+ (cadr A ) (cadr B) )
    		(+ (caddr A ) (caddr B ) )
    	)
    )
    
    (defun SelSet:Entsel (tresc filter / OldNoMutt MSel OutVal 
     *error* ) 	(defun *error* ( msg / ) 
    		(if (not (null msg ) )	(progn (princ "\nSelSet:Entsel:*error*: " ) (princ msg ) (princ "\n")	) )
    	)      
    
    	(setq tresc (strcat "\n" tresc ": ") )
    	(prompt tresc )
    	
    	(setq OldNoMutt (getvar 'NOMUTT))	
    	(setvar 'NOMUTT 1)	
    	(setq MSel
    		(if (null filter)
    			(vl-catch-all-apply 'ssget (list ":S:E" ))
    			(vl-catch-all-apply 'ssget (list ":S:E" filter ))
    		)
    	)
    		
    	(setvar 'NOMUTT OldNoMutt )
    	(if (vl-catch-all-error-p MSel)
    	(progn
    		(prompt (vl-catch-all-error-message MSel))
    	)
    	(progn
    	  (if MSel (progn		
    		(setq OutVal (vlax-ename->vla-object  (ssname MSel 0)) )			
    	  ))
    	)
    	)
    	OutVal
    )
    
    
    (defun ZWCAD:GetDist (tresc domyslny / Wynik trescformat liczba  
    	*error* ) 	(defun *error* ( msg / ) 
    		(if (not (null msg ) )	(progn (princ "\nZWCAD:GetDist:*error*: " ) (princ msg ) (princ "\n")	) )
    	)      	
    	(if domyslny (if (numberp domyslny) (setq tresc (strcat tresc "<" (rtos domyslny 2 4) ">") )))
    	(setq tresc (strcat "\n" tresc ": "))
    	(setq liczba(vl-catch-all-apply 'getdist (list tresc )))
    	(if (vl-catch-all-error-p liczba)
    	(progn
    		(prompt (vl-catch-all-error-message liczba))
    		(setq Wynik nil )
    	)
    	(progn
    	  (if (null liczba) 
    		(setq Wynik domyslny )
    		(setq Wynik liczba)
    	  )
    	)
      )
      Wynik
    )
    
    
    (defun ZWCAD:Getpoint (tresc P0 domyslny / SelPt Wynik 
     *error* ) 	(defun *error* ( msg / ) 
    		(if (not (null msg ) )	(progn (princ "\nZWCAD:Getpoint:*error*: " ) (princ msg ) (princ "\n")	) )
    	)      
    ;(ZWCAD:Getpoint tresc P0 domyslny )
    	(setq tresc (strcat "\n" tresc ": "))
    	(if (not(null P0))
    		(setq SelPt(vl-catch-all-apply 'getpoint (list P0 tresc )))
    		(setq SelPt(vl-catch-all-apply 'getpoint (list  tresc )))
    	)
    	(if (vl-catch-all-error-p SelPt)
    	(progn
    		(prompt (vl-catch-all-error-message SelPt))
    		(setq Wynik nil )
    	)
    	(progn				
    	  (if (null SelPt) 
    		(setq Wynik domyslny )
    		(setq Wynik SelPt)
    	  )
    	)
      )
      Wynik
    )
    
    
    (defun ZWCAD:GetString (tresc domyslny / 
    	*error* ) 	(defun *error* ( msg / ) 
    		(if (not (null msg ) )	(progn (princ "\nZWCAD:GetString:*error*: " ) (princ msg ) (princ "\n")	) )
    	)      
    	(setq tresc (strcat "\n" tresc ": "))
    	(String:Get tresc domyslny)
    )
    
    (defun String:Get (komunikat defVal / Wynik tekst 
    	*error* ) 	(defun *error* ( msg / ) 
    		(if (not (null msg ) )	(progn (princ "\nString:Get:*error*: " ) (princ msg ) (princ "\n")	) )
    	)      
    	;	(setq komunikat "podaj tekst" )
    	;	(setq defVal "SLU" )
    	 
    	(if defVal (if (not(= defVal "")) (setq komunikat (strcat komunikat "<" defVal ">:" ) )) )
    	(setq tekst(vl-catch-all-apply 'getstring (list komunikat )))
    	(if (vl-catch-all-error-p tekst)
    	(progn
    		(prompt (vl-catch-all-error-message tekst))
    		(setq Wynik nil )
    	)
    	(progn
    	  (if (null tekst) 
    		(setq Wynik defVal )
    		(if (= tekst "")
    			(setq Wynik defVal )
    			(if (= tekst ".")
    				(setq Wynik "")
    				(setq Wynik tekst)
    			)
    		)
    	  )
    	)
      )
      Wynik
    
    )

     

    Szyk.lsp

  3. A na drugi, to ten kod z tablicami dla mnie był bardziej czytelny niż z kolekcjami.

    Refaktoryzacja w celu usunięcia kodu spagetti przez wydzielenie funkcji to dobry plan. Ale zmiana typy danych z tablicy na kolekcję, to po żeby za chwilę zmieniać kolekcję na tablicę to ma skutek dokładnie odwrotny.

    Myślę, że lepszym planem byłoby oddzielenie operacji typu interakcja z użytkownikiem, przeliczenie punktów rysowanie. np tak

    Public Function ZapytajOPunkt(komunikat As String)
        ZapytajOPunkt = ThisDrawing.Utility.GetPoint(, komunikat)
    End Function
    
    Public Function przeliczPunkty(NAROZNIK As Variant)
    	ReDim p(7) As Double
    	p(0) = NAROZNIK(0): p(1) = NAROZNIK(1)
    	p(2) = NAROZNIK(0) + 50: p(3) = NAROZNIK(1) + 30
    	p(4) = NAROZNIK(0) + 100: p(5) = NAROZNIK(1) + 30
    	p(6) = NAROZNIK(0) + 100: p(7) = NAROZNIK(1)
    	przeliczPunkty = p
    End Function
    
    Public Function rysuj(p)
        Dim poly As ZcadLWPolyline
        Set poly = ThisDrawing.ModelSpace.AddLightWeightPolyline(p)
        poly.ConstantWidth = 1
    End Function
    
    
    Private Sub Test()
    ' frm_test.Hide
    
        Dim NAROZNIK As Variant
        NAROZNIK = ZapytajOPunkt("Podaj punkt początkowy:")
    
        Dim p() As Double
        p = przeliczPunkty(NAROZNIK)
    
        rysuj (p)
    
    End Sub

    Dzięki temu

    • pracujesz szybciej, bo jesteś niezależny od okna
    • możesz w innej funkcji testującej wywołać np tylko rysuj(p) na danych sztucznie spreparowanych dzięki czemu masz pewność że ten obszar DZIAŁA.
    • masz wszystkie operacje związane z reprezentacją grafiki w jednym miejscu. więc jeśli chcesz w innym miejscu aplikacji narysować podobną polilinię, to nie musisz pamiętać że masz jeszcze zmienić jej szerokość.
    • Jeśli chcesz zmienić polilinię, np na szerszą, albo podmienić na inny typ elementu np blok, robisz to tylko w jednym miejscu, w funkcji rysuj, a nie musisz szukać w innych miejscach aplikacji gdzie to jeszcze i po pozmieniać.
  4. Testowałem na Visual Studio 2010.

    Miałem dostepne ZWCAD 2020 Type Library w pliku

    C:\Program Files\Common Files\ZWSoft Shared\ZWCAD18.tlb 

    i ZWCAD Type Library w plik

    C:\Program Files\Common Files\ZWSoft Shared\ZWCAD17.tlb

    Ale przeszedłem na zakładkę  Browse, wybrałem plik

    c:\Program Files\ZWSOFT\ZWCAD 2020\ZWCAD.exe

    Przestrzeń ZWCAD stała się dostępna.

    using ZWCAD;

    Plik

    C:\Program Files\Common Files\ZWSoft Shared\ZWCAD18.tlb 

    Nie jest częścią SDK. Na innym komputerze gdzie nie mam SDK ten plik jest dostępny, więc pewnie w Pana przypadku wystarczy wskazać plik nie z listy tylko wybierając z dysku.

  5. Przykład zapisu i odczytu XDaty może być taki:

    
    Public Sub ZapisXDaty()
        Dim linia As ZcadEntity
        
        Dim XType(0 To 9) As Integer
        Dim XData(0 To 9) As Variant
        Dim reals3(0 To 2) As Double
        Dim worldPos(0 To 2) As Double
        
        XType(0) = 1001: XData(0) = "TestowaAplikacja"
        XType(1) = 1000: XData(1) = "przykładowy tekst"
        XType(2) = 1003: XData(2) = "0"
        XType(3) = 1040: XData(3) = 1.23479137438413E+40
        XType(4) = 1041: XData(4) = 1237324938
        XType(5) = 1070: XData(5) = 32767
        XType(6) = 1071: XData(6) = 32767
        XType(7) = 1042: XData(7) = 10
        
        reals3(0) = -100.23: reals3(1) = 100.23: reals3(2) = -20
        XType(8) = 1010: XData(8) = reals3
    
        worldPos(0) = 200.23: worldPos(1) = 200.23: worldPos(2) = -10
        XType(9) = 1011: XData(9) = worldPos
        
        Set linia = Sel("Wybierz element")
        linia.SetXData XType, XData
    
    
    End Sub
    
    Public Sub OdczytXDaty()
        
        Dim selected As ZcadEntity
        
        Dim xdataOut As Variant
        Dim xtypeOut As Variant
        
        Set selected = Sel("Wybierz element")
        
        selected.GetXData "", xtypeOut, xdataOut
        For Each v In xdataOut
            If VarType(v) >= 8192 Then
                ThisDrawing.Utility.Prompt v(0)
                ThisDrawing.Utility.Prompt v(1)
                ThisDrawing.Utility.Prompt v(2)
            Else
                ThisDrawing.Utility.Prompt v
            End If
        Next
        
    End Sub
    
    Public Function Sel(ByVal txt As String) As Object
    
        Dim obj As ZcadEntity
        Dim px As Variant
        On Error Resume Next
            ThisDrawing.Utility.GetEntity obj, px, txt
        On Error GoTo 0
        Set Sel = obj
    
    End Function